Use python Django for web pages
- 2020-04-02 13:14:04
- OfStack
1. Create a django project
Use django-admin.py to startproject MyDjangoSite
2. Create a view
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201311/2013110409262310.png ">
From django.http import HttpResponsedef hello(request):
Return HttpResponse(" my first simple python django project." )
3. Modify urls.py
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201311/2013110409262311.png ">
We add a row to urlpatterns: (r '^hello/$', hello), which is called a URLpattern and is a Python tuple. The first element in a tuple is a pattern matching string (regular expression); The second element is the view function that that pattern will use.
The regular expression string begins with the letter "r". It tells Python that this is a raw string and that it doesn't need to deal with backslashes (escape characters) inside. It is generally a good habit to add "r" before using regex!
4. Run python manage.py runserver
How to start the development server can be seen here
http://127.0.0.1:8000/hello
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201311/2013110409262312.png ">