Django code explanation:
The top lines import the Django library:
from django.confimport settings
from django.conf.urlsimport patterns
from django.httpimport HttpResponse
from django.core.managementimport execute_from_command_line
If you open the link /hello/, the webserver will call the index() function. We map the url to the function using:
urlpatterns = patterns('',(r'^hello/$', index),)
In Django we have url friendly urls. This means you do not have a url that ends in /id=1359835, but instead we have the directory as name. Finally, we set some default settings using settings.configure.
If you want to start with python web development, you could use a web framework named Django. It is designed to be fast, secure and scalable. It comes with an object-relational mapper (ORM), which means that objects in Python are mapped to objects in a database.
Applications created with Django are separated in three separate layers: model (database), view (appearance) and controller (logic), or shortly themodel-view-controller (MVC) architecture.
Pick from sqlite3, postgresql_psycopg2, mysql or oracle. Name is the name of your database. If you use SQLite the database will be created automatically. For MySQL and Postgresql you need to create the database yourself. Go up one directory to /mysite/ and run:
python manage.py runserver
The terminal should say:
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run'python manage.py migrate' to apply them.
August16,2015 - 14:45:29
Django version 1.7.1, using settings 'myapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16/Aug/201514:45:35]"GET / HTTP/1.1"2001759