Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. Python Django takes care of the repetitive work for you so that you don’t have to reinvent the wheel all over again.
You can install Django using
1 |
$pip install django |
For other ways of installation, visit this.
Since this is the first time we are using Django there is some initial setup to do. We need to auto generate some code that establishes the Django project.
From the command line,
1 |
$ django-admin startproject mysite |
This will create a folder ‘mysite ‘ in your current directory. Do avoid python names of different functionalities as names for the folder. Ex. Django and test are not good choices since they create conflict on calling.
Also, with Django you do not put your code under your web server’s root directory. We always place it outside.
Let’s look at what startproject created:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
These files are:
Let’s verify whether our Django works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
root@localhost:/home/enfa/Desktop/GlobalSQA/mysite# python manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. July 07, 2017 - 15:28:53 Django version 1.11.3, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. |
You can safely ignore the warning for now.
Yipppe! We have started the Django server! Let’s go see how it looks like.
Note This is only for studying. When it comes to production setting, use Apache servers or similar.
By default the port is 8000. But you can change it using the command line. Say you want to change it to 8080
1 |
$ python manage.py runserver 8080 |
Full docs for the development server can be found in the runserver reference
To know how to edit and configure your webpages, check out https://docs.djangoproject.com/en/1.11/intro/tutorial01/
For more details visit,
https://www.djangoproject.com/
https://docs.djangoproject.com/en/1.11/#index-first-steps
https://www.djangoproject.com/start/
https://docs.djangoproject.com/en/1.11/
https://tutorial.djangogirls.org/en/django_start_project/
Leave a Reply