Installation of 1.python
A lot of information about Django and Python development on the web, this piece I am preparing to use this two together to engage in a web-based thing to start learning now, write something to record the experience.
The development environment is windows, so we go to the Python website to download the installation package for the 64-bit Windows operating system:
Https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi
This version adds directly to the system's environmental variables (spit out the configuration of various development environment variables).
Installation of 2.Django
Install Django below: Yes, I don't know if you've seen the rescued Jiang GE.
https://www.djangoproject.com/download/1.8/tarball/
Download it is. tar.gz, can use 7z decompression, here recommend 7z this free decompression software.
7z:
Http://downloads.sourceforge.net/sevenzip/7z920-x64.msi
Go to the unpacked directory: a command to fix the installation
python setup.py Install
See if the installation is ready:
Import Django
Django. VERSION
After that, the version information is installed.
Database What binding work we do not do, this version of Python by default comes with SQLite, so, basically enough.
3. Build a project that displays time
Open cmd, get into a directory, whatever directory:
Django-admin startproject ProjectName
What the Startproject has created:
mysite/
__init__.py
manage.py
settings.py
urls.py
Include the following files:
__init__.py: Let Python treat the directory as a required file for a development package (that is, a set of modules).
manage.py: A command-line tool that allows you to interact with the Django project in a number of ways.
settings.py: The setup or configuration of the Django project.
urls.py: The URL Declaration of the Django Project, the list of contents of the Django-supported site
Create a new views.py under the MySite directory (ProjectName)
From django.http import httpresponseimport datetime,calendarimport timedef current_datetime (Request): now = Time.strftime ('%y-%m-%d-%h-%m-%s ', Time.localtime (Time.time ())) HTML = "
Modify the uls.py to:
From Django.conf.urls import patterns, include, urlfrom django.contrib import adminfrom mysite.views import Current_datet Imeurlpatterns = Patterns (', # Examples: # URL (r ' ^$ ', ' mysite.views.home ', name= ' home '), # URL (r ' ^blog/') , include (' Blog.urls ')), #url (R ' ^admin/', include (Admin.site.urls)), (R ' ^time/$ ', current_datetime),)
Go to the ProjectName folder and run the python manage.py runserver command
Reference documents:
A knowledge base for IBM:
http://www.ibm.com/developerworks/cn/linux/l-django/
Djangobook Online version: (above some of the code has errors, you need to have a little debugging skills)
http://djangobook.py3k.cn/chapter03/
Django Official Documentation:
http://django-chinese-docs.readthedocs.org/en/latest/
Python +django builds the Web development environment initially, showing the current time