Build Django on Linux

Source: Internet
Author: User
Tags install django

    • Step1:install Django

#sudo Apt-get Install Python-django

Verify that the installation is successful and that you can import the Django package in Python
#python
>>>import Django
>>>django. VERSION

I'm using a 1.10.7.
>>>quit ()

    • STEP2: Creating a Project

>>django-admin Startproject Djangoproject

    • STEP3: Start Service

>>python manage.py Runserver
Default is 127.0.0.1:8000
Open a browser to view Http://127.0.0.1:8000/,it works


    • STEP4: Create my app Agenda

>>python manage.py Startapp Agenda

    • STEP5: Writing view.py and URLs config for agenda applications

>>CD Agenda;vi views.py

>>CD Agenda;vi urls.py

Knowledge points: The UP arrow ^ and dollar sign $ symbol are very important. The up arrow requires the expression to match the head of the string, the dollar
The symbol requires an expression to match the tail of the string. R represents an original string. So that you can avoid regular expressions
There are too many escape characters.


>>CD Djangoproject/djangoproject; VI urls.py

Note: The URLs here must be in the Djangoproject/djangoproject directory, not the Djangoproject directory, where the wrong directory, input Http://127.0.0.1:8000/agenda, You will get an error. URL matching is not found.

    • STEP6: Restart Service

>>python manage.py Runserver

To view Http://127.0.0.1:8000/agenda

    • STEP7: In order to make the intranet other machines can be measured, you can set the Sunserver IP for any

>>python manage.py Runserver 0.0.0.0:8090

On other machines, just enter the native IP and 8090 ports to access

If the browser on the other machine does not open the Http://192.168.x.x:8000/agenda, you need to configure the host to allow access


>>CD Djangoproject/djangoproject;vi settings.py

Allowed_host = [' * ']
Note: It is not recommended to set this access host,true only at Debug=false, this is only for testing

Build Django on Linux

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.