Django Learning---environment building

Source: Internet
Author: User

1 Installing Django

A:PIP Installation

   pip installDjango==版本号

B: Source Installation https://www.djangoproject.com/download/

tar-xvzf django-1.9.5.tar.gz

CD django-1.9.5

Python setup.py Install (premise: Setuptools is already installed)

2 See if you have installed

Import Django

Django. VERSION

#(1, 9, 5, ‘final‘, 0)

3 about Django some files

urls.py: URL entry (URL routing rule), associated to a function in the corresponding views.py (or generic Class), the access URL corresponds to a function.

views.py: processing the user requests, from the urls.py corresponding to, through the rendering templates in the page can display content, such as the login user name, the user requested data, output to the Web page.

models.py: related to database operations, this is used when depositing or reading data, of course, you can not use when the database is not used.

forms.py: The form, the user enters the data to submit in the browser, the data verification work as well as the input box generation and so on work, certainly also may not use.

#Templates folder (you need to create it yourself): views.py in the function of rendering templates HTML template, the dynamic content of the Web page, of course, can use caching to improve speed.

admin.py: Backstage, you can have a powerful background with a very small amount of code.

settings.py: Django settings, configuration files, such as DEBUG switches, static file locations, and so on.

4 basic commands

4.1. Create a new Django project:

Django-admin startproject Project-name (Project-name for own project name)ordjango-admin.py startproject project-name

4.2. Create a new app:

Python manage.py startapp app-nameordjango-admin.py startapp app-name

4.3. Synchronize the database:

Python manage.py syncdb1.7. 1 and later need to use the following command python manage.py makemigrationspython manage.py Migrate

This method creates a table, and when you add a class to the models.py, you can run it to automatically create a table in the database without creating it manually.

Note: If you modify an existing models, Django before Django 1.7 cannot change the table structure automatically.

4.4. Start the project service:

Python manage.py Runserver # when the prompt port is occupied, kill consumes the program or can use another port: Python manage.py runserver port number # Listen Ippython manage.py runserve R 0.0.0.0:8000
#这个和apache的配置差不多

4.5. Clear the database:

Python manage.py Flush

4.6. Create a Super Administrator:

Python manage.py Createsuperuser

4.7. Import and Export data:

Python manage.py dumpdata appname > Appname.jsonpython manage.py loaddata Appname.json

4.8.Django Project Terminal:

Python manage.py Shell

4.9. Database command line:

Python manage.py Dbshell #mysql这类的数据库会提示输入用户密码

4.10. More Commands:

Python manage.py# can see a detailed list

Django Learning---environment building

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.