Django First Application
Creating First Views in Django
$ django-admin startproject mysite
Let’s look at what startproject created:
$ python manage.py runserver
Changing the port
By default, the runserver command starts the development server on the internal IP at port 8000.
If you want to change the server’s IP, pass it along with the port
python manage.py runserver 8080
Projects vs. apps
Apps: An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app.
Project: A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
$ python manage.py startapp polls
That’ll create a directory polls, which is laid out like this:
Writing First Views: -
from django.http import HttpResponse
return HttpResponse("Hello, world. You're at the polls index.")
This is the simplest view possible in Django. To call the view, we need to map it to a URL - and for this we need a URLconf.
To create a URLconf in the polls directory, create a file called urls.py. Your app directory should now look like: