Django (2): Launch and first app

Source: Internet
Author: User

Reference: HTTPS://DOCS.DJANGOPROJECT.COM/EN/1.9/INTRO/TUTORIAL01/

1. Go to the desired directory,

$ sudo django-admin startproject ProjectName

2. Start the server

Go to the manage.py directory.

$ sudo python manage.py runserver 0.0.0.0:8000

3. Create an App

1) Create

Enter the manage.py directory

$ sudo python manage.py startapp polls

Polls is the file name of the app

2) Modify View

Enter polls

$ sudo vi views.py

Add to

HttpResponseIndex(requestHttpResponse("Hello, World.") You ' re at the polls index. )

3) Create URL

Create urls.py under the polls file

polls/urls.py

$ sudo vi urls.py

Add to

From Django.conf.urls import URL

From. Import views

urlpatterns = [url (r ' ^$ ', views.index,name= ' index '),]

4) point to URL

Open mysite/mysite/urls.py (Note that this is a subfolder mysite,url.py already exists)

Add to

From Django.conf.urls import Url,include

From Django.contrib Import admin

urlpatterns = [url (r ' ^polls/', include (' Polls.urls ')), url (' ^admin/', admin.site.urls),]

(Regular expression: http://www.ziqiangxuetang.com/regexp/regexp-syntax.html)

5)

sudo python manage.py runserver

You can open it at the URL/polls.

Django (2): Launch and first app

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.