III. Running web services
Click on the green triangular arrow to start running the web service, or of course you can use the command line
cd project path
python manage.py runserver
I. Create App
You can include multiple APPs in each django project, and you can think of APPs as subsystems, submodules, functional components, etc. in a large project that are relatively independent of each other, but also connected. All apps share project resources, and there is a terminal terminal entry at the bottom of the project, enter the following command to create an app module called myapp.
python manage.py startapp myapp
II. Writing routes
Earlier we had an introduction to Django's architecture, which has an urls.py, and the routes are all in the urls file, which maps the url entered by the browser to the appropriate business processing logic.
Import the views file of the corresponding app, here is to import the corresponding views in myapp
Writing routing rules
# url(r'^admin/', include(admin.site.urls)),
III. Writing business logic
In the last step we have referenced views.py inside myapp, but our business logic is not written yet, we need to write the business logic in views.py
Punching views.py, we start by importing the HttpResponse module to be used
Define an index method, remember the code we used when writing the route in the live diagram-1? views.index, the index is to call this method to return an HttpResponse response to the user, which index (request) in the request parameter is required, the request is used to handle the response request
IV. Running again
Click on the green triangle arrow, then type http://127.0.0.1:8000/ Visit.
If nothing else, the error above will appear, haha, this is a deliberate mistake by the coder, take a look at the error prompt what, reported 404 error, just can't find the corresponding interface, and then look back at our previous in urls.py
This means that when the URL path is entered as index, the views.index screen is displayed, but we only enter http://127.0.0.1:8000/ So he won't be able to find the corresponding page, which naturally reports a 404 error
Method 1: http://127.0.0.1:8000/index can then (do sth)
Method 2: Change the rules in urls.py to
>>1、Happy June 1st Childrens Day In the world of blockchain were all kids2、Japans Finance Minister Taro Aso Blockchain technology needs to be developed with caution3、CAS releases big data on World Cup fresh economy Daily Fresh and other head platforms take 75 share4、What the hell is a blockchain anyway Read the comic and youll understand5、jQuery Zero Basics Getting Started H AJAX