Home >Backend Development >Python Tutorial >Use python Django to create web pages

Use python Django to create web pages

高洛峰
高洛峰Original
2016-12-27 15:08:271675browse

1. Create a django project
Use django-admin.py startproject MyDjangoSite. Refer here

2. Create a view

使用python Django做网页

from django. http import HttpResponsedef hello(request): Return HttpResponse("My first simple python django project.")

3. Modify urls.py

使用python Django做网页

We add a line to urlpatterns: (r'^hello/$', hello), this line is called URLpattern, which is a Python tuple. The first element in the tuple is the pattern matching string (regular expression); the second element is the view function that will be used by that pattern.
Regular expression string starting with letter "r". It tells Python that this is a raw string and does not need to deal with the backslashes (escape characters) inside. It is generally a good habit to add "r" before using a regular expression!

4. Run python manage.py runserver
How to start the development server can be seen here
http://127.0.0.1:8000/hello

使用python Django做网页


For more articles related to using python Django to make web pages, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn