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
$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,
$ 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:
These files are:
Let’s verify whether our Django works.
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
$ 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,
Leave a Reply