Django Framework builds Web services

Source: Internet
Author: User

First, the tool

Environment: Windows 7

Python 2.7.7:https://www.python.org/downloads/release/python-2713/ps: The address provided here is the current version of the latest 2.7, should not be very different

django-1.11.3:https://www.djangoproject.com/download/

Second, installation

1.python installation, download the installation files, all the way next. After the installation is complete, add the installation directory to the environment variables.

Environment variable Add method: Right click on the computer on the desktop, click on the properties, and then on the popup page, click on the left side of the advanced system settings, this time we will see "Environment variables", click to see the user variables and system variables, in the system variables, the keyboard press p, search to the path, double click or click "Edit" , add the path (for example: C:\python27, look at the installation directory) to the input box at the end, pay attention to;

2.django installation, download the good files, unzip to the Python installation directory, open the Django directory, shift+ right click, you can see, in the current directory Open command line, click into the command line. Input command: Python setup.py install

Wait for the installation to complete, and then add the Python27\scripts,python27\lib\site-packages\django-1.11.3-py2.7.egg\django\bin under Python to the environment variable. The installation is complete.

We can check the command line by entering the following command:

>>python into Python

>>import Django

>>django.getversion ()

If you can see that "1.11.3" is displayed and the installation is complete, check that the installation procedure is not a problem if you make an error.

Third, Hello World

1. Create a project

Django-admin startproject MySite MySite is the name of the project created

Note:

1). Some tutorials are written in django-admin.py Startproject MySite This is the creation of unsuccessful, do not know is wrong, or the version is not the same. I'd prefer to believe it was a clerical error

2). In which directory to execute this command, the project is saved in the directory, such as C: Execute, then the C packing directory will be created MySite

2. Create an application in the MySite directory HelloWorld

Python manage.py Startapp HelloWorld then we can see one more HelloWorld folder under Mysites

3. Modify the views.py file under HelloWorld

#-*-Coding:utf-8-*-
From __future__ import unicode_literals

From django.shortcuts Import Render

From django.shortcuts import HttpResponse
# Create your views here.


def index (Request):
#request. Post
#request. GET
Return HttpResponse ("Hello world!")

4. Modify the urls.py file under Mysites

From Django.conf.urls import URL
From Django.contrib Import admin
From HelloWorld import views #这一行是导入helloworld下的views

Urlpatterns = [
#url (R ' ^admin/', admin.site.urls) This is commented out and comes with background management
URL (r ' ^index/', Views.index),
]

5. Start the server

Python manage.py runserver 127.0.0.1:8000 wait for server to start complete

6. Open the browser and enter http://127.0.0.1:8000/index/

If everything is OK, we should now see the page showing Hello world!

At this point our most basic construction work is completed. If you want to make a more complex website, please prepare the appropriate knowledge

Django Framework builds Web services

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.