Django Study Notes for crazy summer vacation (1)
The Django book
Video: csvt Django video
1. Create a project
Django-Admin. py startproject mysite.
2. Run the Development Server
Python manage. py runserver
3. File structure
Mysite/
── Manage. py
── Mysite
── _ Init _. py
── Settings. py
── URLs. py
── Wsgi. py
Mange. py: a command line tool that allows you to interact with this Django project in multiple ways. Type python manage. py help to view help and specify the configuration file setting. py.
The mysite folder in the mysite folder is a python package _ init _. py. The package must wait for the file, and its content is empty.
Setting. py project configuration file. For example, root_urlconf = 'mysite. urls' configures the URL file location.
URLs. py URL configuration file
4. View and URL Configuration
Create a view. py file in the mysite folder under mysite (the name can be any one)
Input
from django.http import HttpResponse def output(request,str): html = "
Add (R' ^ input/(\ W +) ', output) in URLs. py ),
from django.conf.urls import patterns, include, url from django.contrib import adminfrom mysite.view import outputadmin.autodiscover()urlpatterns = patterns('', # Examples: # url(r'^$', 'mysite.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), (r'^input/(\w+)',output), )
Then Python manage. py runserver runs the Development Server
Enter http: // 127.0.0.1: 8000/input/hello in the browser, and you will be able to see wellcom in Hello input http: // 127.0.0.1: 8000/input/Wellcome.
5. Now let's talk about what they are doing.
View. py defines a method. The first parameter must be the httprequest variable, followed by the variable passed by URLs. Returns an httpresponse object.
Usrls. py is a URL configuration file that defines what address will be followed when you enter in your browser.
(R' ^ input/(\ W +) ', output) tuples. The first one is a regular expression (Python Regular Expression Introduction ). Http://blog.csdn.net/billvsme/article/details/23520007), represents the variable enclosed in parentheses, to be passed to the subsequent function; the second is the function to be responded, to add from mysite. View import output to tell the location of Python output.