Because this tutorial needs to use some of the Anaconda operations, if you do not understand the anaconda of the operation of the students can read this article Python introductory learning Anaconda.
Create a python3+ development environment
Input directly in terminal:conda create-n newenv python=3.5
Enter our new development environment NEWENV
Linux:source Activate newenv
Window:activate newenv
Installing django2.0
Directly in the terminal input: pip install Django , then the system will automatically download the latest version of django2.0.2.
Create a Django Project
enter directly in the terminal: django-admin startproject MySite
then enter mysite This file directory, in terminal input: CD mysite/
See what's in the catalog, in the terminal input: ls
To add, you can click here to see the difference between Django-admin and manag.py.
Then we continue to enter MySite this directory in the through LS view what content.
Now let me explain what these files are for.
- Outermost mysite/: Just a file that contains your project. What it does not affect Django, and you can modify it casually.
- manage.py : a command-line toolkit.
- Inner mysite/ : The directory is a Python package based on your project. Its name is also the Python package name.
- mysite/init. PY: An empty file is meant to indicate that this is a Python package.
- mysite/settings.py: Configuration information for this Django project.
- mysite/urls.py : The URL declaration for the Django Project.
- mysite/wsgi.py : An entry point for services provided by a WSGI-compliant web server.
Start the server
With the above operation we have created the good one Django project, we go back to the outermost mysite/this directory, and then in the terminal input:python manage.py runserver start the server, after success will appear below.
Then we visit http://127.0.0.1:8000/in the browser, and the following appears.
So far we've succeeded in creating a new Django project and running it up.
Create an App
It is worth mentioning the difference between the project and the application: An application is a function in a WEB program, such as a blog application, a voting application. A project is a collection of many basic applications
Enter the command directly in the terminal: python manage.py startapp staffadmin
Successfully created Staffadmin This application we can go to this file directory to see which files are.
I'll explain a few of the files we need to use here.
- admin.py: This is the configuration management background data.
- models.py : Each of these classes can be likened to every table in a database.
- views.py : Used primarily as a front-end interaction.
- urls.py: Used as a configuration route.
Create a View
Open staffadmin/views.py This file, write down the following code
Then we create a new urls.py in the Staffadmin directory, write down the following code
Also to configure the mysite/urls.py, write down the following code
Then we access the Http://127.0.0.1:8000/staffadmin/index through the browser
If successful, you will see "This is my first application" in the browser.
Next, I will continue to explain the use of models and the use of admin.
python3.5+django2.0 Quick Start (i)