Previous Page Next Page

Q&A

Q.The URL dispatcher allows me to send arguments to the view function directly in the URL. Can I still send additional GET and POST information in the HTTP request?
A.Yes. The ability to parse the URL and obtain arguments to pass the view function is a powerful feature of Django. However, you still can retrieve data that is passed as part of a GET and POST request.
Q.Is the HttpResponse object the only way to generate web pages in Django?
A.No. Several subclasses of the HttpResponse object can be used. For example, you can use HttpResponseRedirect to redirect pages to a different URL or HttpResponseNotFound to automatically return a 404 error. Also, as you will learn in future hours, you can use the render_to_response object to use a template to generate the web page.
Q.As I create more and more applications, I can see that the URLconf file could get cumbersome. Is there a way to break URLconf into separate files?
A.Yes. In fact, that is what is happening with the admin interface you have already enabled. Look at the line of code for that admin interface in the URLconf file:
(r'^admin/', include('django.contrib.admin.urls')),

Instead of pointing to a view in your urls.py file, it includes an urls.py file that is located in the django/contrib/admin/ directory. You can also create separate urls.py files for your applications and store them in the application directory. Then have the URLconf file include each urls.py file based on the URL pattern for the application.

Previous Page Next Page