mirror of
https://github.com/django/django.git
synced 2024-12-30 21:16:26 +00:00
a0f8c52ae2
e.g. ResourceWarning: unclosed <socket.socket [closed] fd=6, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from urllib.request import urlopen
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from .models import Person
|
|
|
|
|
|
def example_view(request):
|
|
return HttpResponse('example view')
|
|
|
|
|
|
def model_view(request):
|
|
people = Person.objects.all()
|
|
return HttpResponse('\n'.join(person.name for person in people))
|
|
|
|
|
|
def create_model_instance(request):
|
|
person = Person(name='emily')
|
|
person.save()
|
|
return HttpResponse('')
|
|
|
|
|
|
def environ_view(request):
|
|
return HttpResponse("\n".join("%s: %r" % (k, v) for k, v in request.environ.items()))
|
|
|
|
|
|
def subview(request):
|
|
return HttpResponse('subview')
|
|
|
|
|
|
def subview_calling_view(request):
|
|
with urlopen(request.GET['url'] + '/subview/') as response:
|
|
return HttpResponse('subview calling view: {}'.format(response.read().decode()))
|
|
|
|
|
|
def check_model_instance_from_subview(request):
|
|
with urlopen(request.GET['url'] + '/create_model_instance/'):
|
|
pass
|
|
with urlopen(request.GET['url'] + '/model_view/') as response:
|
|
return HttpResponse('subview calling view: {}'.format(response.read().decode()))
|