Want to learn web development, and still want to continue python, go online a search, it is gratifying that Python do background development is very powerful, the front-end is of course: HTML and css,javascript ....
These three are a bit of a text type of feeling, often see should be OK
Looking for a job online look, feel Django this architecture is good ah, OK to learn this, learning materials is the official document ...
It's python2.7.8.
Installation of 1.django
On the official website 1.6.8, after decompression, renamed "Django", the django/setup.py in the path of admin.py modified well,
Then in cmd: Python django/setup.py Install
Test for installation success: in the Python shell: Import django;print django.get_version (); If the 1.6.8 is installed successfully, if the error is unsuccessful.
2. Create a first project
In cmd: django-admin.py startproject mysite (project name)
You'll see a MySite folder in the Python path.
3. Running the server
CMD in: mysite/manage.py runserver
will see:
Validating models ...
0 errors found
October 22, 2014-15:50:53
Django version 1.5.11, using Settings ' mysite.settings '
Development server is running at http://127.0.0.1:8000/
Quit the server with Control-c.
(127.0.0.1:800 is the host URL, open will see Django prompt yo)
3. Create an app (actually it's pretty simple now, just one step, toss for two days)
There are many apps in the Installed_apps of MySite's setting.py,
Django.contrib.auth–an authentication System.
Django.contrib.contenttypes–a Framework for content types.
django.contrib.sessions–a session Framework.
Django.contrib.sites–a Framework for managing multiple sites with one Django installation.
django.contrib.messages–a Messaging Framework.
Django.contrib.staticfiles–a framework for managing static files.
For the convenience of commonly used examples, these applications are included as default configurations. Each of these apps uses at least one database table, so we need to create these tables before using them. CREATE table: Python manage.py syncdb
The difference between project and app: app is a Web application that does something, such as a microblog system, a public records database, or a simple test application.
Notice here, attention. : Be sure to put your apps under project (so that you can be a module loader), or if both (app and project setting.py) are not in a folder, add the path when loading in setting.py ...
Create App,cmd:python manage.py Startapp polls
We created a simple app:polls here, put the polls under the MySite just fine.
Rewrite in the polls/models.py
From django.db import Modelsclass Poll (models. Model): question = models. Charfield (max_length=200) pub_date = models. Datetimefield (' Date published ') Class Choice (models. Model): poll = models. ForeignKey (Poll) Choice_text = models. Charfield (max_length=200) votes = models. Integerfield (default=0)
Then add "Polls" to the Installed_apps in mysite/setting.py:
' Django.contrib.sessions ', ' django.contrib.sites ', ' django.contrib.messages ', ' Django.contrib.staticfiles ', # Uncomment the next line to enable the admin:# ' Django.contrib.admin ', # uncomment the next line to enable admin Documentati on:# ' Django.contrib.admindocs ', ' polls ',
Then run Cmd:python manage.py SQL polls
When you see:
BEGIN; CREATE TABLE"Polls_poll" ("ID"serial not NULL PRIMARY KEY,"question"VARCHAR (200) not NULL,"pub_date"timestamp with time zone not NULL); CREATE TABLE"Polls_choice" ("ID"serial not NULL PRIMARY KEY,"poll_id"Integer not NULL REFERENCES"Polls_poll"("ID") Deferrable initially DEFERRED,"Choice_text"VARCHAR (200) not NULL,"votes"integer not NULL); COMMIT;
You will succeed!! Ha ha
First project, the first app to cry