The--django of Reverse teaching series (i) "No need to know the web framework"

Source: Internet
Author: User
Tags install django pip install django

This is the end of the Web site, or a more general purpose server. Server, that is, if you use another computer ("client") to send it a request, it will return something-if you send a message to a random machine, it does not necessarily ignore you. To have a machine respond to you, you have to meet these conditions


    • It's not in a shutdown state.

    • It can receive your message, and you can receive it.

    • It is running a service program

    • It runs a program that knows how to respond to your request


The 1th is the power-on, the 2nd is the Internet (but here a bit complex), 3rd and 4th require a program, plainly on a xxx.py, request to be able to receive the request, and generally return a string containing HTML format (not necessarily have a corresponding HTML file). and entering an address into the browser's address bar is a (most common) request.

The first Django feature described here is that you can get the full service program by simply giving the address and the corresponding HTML. However, as a framework, nature will not be as simple as writing these two, but in a common (and therefore slightly complex) project (a set of files), write what you need in certain key locations. As a demo, the first example is to request a server location and return hello with the following steps:

1. Installing the Django--pip install Django and adding its bin directory to the environment variable


2. Create a project called Hello--Find a place to open the command line, django-admin.py startproject Hello (This command creates a folder containing fixed content)


3. In the innermost layer open urls.py (edit mode), add the following code at the top (multi-line comment is not important):

From django.http import httpresponsedef Hello (Request): Return HttpResponse ("


4. Bring your own line: (In the list urlpatterns, is an element)

Path (' admin/', admin.site.urls),

Change to this:

URL (r ' ^$ ', hello), # ^$ is a regular expression corresponding to a blank line, and Hello is the function to invoke when triggering

"Then" put this again:

From Django.urls Import path

Change to this:

From Django.conf.urls import URL


5. Save the changes, start the service program-there is a manage.py on the first level of the project file, but in order to provide multiple functions, it is scheduled to not be opened directly. Open the command line here, Python manage.py runserver Enter


6. Open any browser, enter "url" 127.0.0.1 carriage return, if you see Hello, then the instructions worked ...


The first article is finished.

(2018-3-5 on Earth)

The--django of Reverse teaching series (i) "No need to know the web framework"

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.