WEB application development using Django [Request processing]

Continued application addition

Django request processing flow

Django's request processing flow is as follows. This time, only the routing view is used, and "Hello, World!" Described in the view function is displayed. Float is a request from the browser-> project1.urls-> posts.urls-> views.index. django_flow.png

Routing (urls.py)

Decide which file to call from the URL pattern that received the request from the browser and the pattern described in the routing file. There are two urls.py in the app and in the project, each defining the behavior distribution in the app and in the project.

Views (views.py)

Returns the behavior of the function called by routing. If it is necessary to call data from the database, describe the description to access the database. Also, describe the operation of processing the data into the required form and passing it to the template.

Let's display Hello, World!

Write a function that returns Hello, World! When a request is received in views.py in the posts folder in the project1 folder created this time.

views.py


from django.shortcuts import render
from django.http import HttpResponse #Add this line

def index(request): #Add this line
    return HttpResponse("Hello, World!") #Add this line

Next, create urls.py in the posts folder and define it in the application (posts).

app name/urls.py


from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

Finally, edit urls.py in the project1 folder.

Project name/urls.py


from django.contrib import admin
from django.urls import path,include #add include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('posts/', include('posts.urls')), #Add this line
]

Start the server, access "http://127.0.0.1:8000/ app name /" (posts in this case), and go to "Hello, World". If "!" Is displayed, it is successful. image.png Template addition

Recommended Posts

WEB application development using Django [Request processing]
WEB application development using Django [Django startup]
WEB application development using Django [Application addition]
WEB application development using Django [Model definition]
WEB application development using Django [Initial settings]
WEB application development using Django [Template addition]
WEB application development using django-Development 1-
WEB application development using Django [Admin screen creation]
WEB application development using django-Development environment construction-
Application development using SQLite with Django (PTVS)
Development of WEB application using Django [Add data from management screen]
Web application using Bottle (1)
(Python) Try to develop a web application using Django
Web application development with Flask
Creating a web application using Flask ②
Web application development memo in python
Build a web application with Django
Creating a web application using Flask ①
Creating a web application using Flask ③
Creating a web application using Flask ④
Application development using Azure Machine Learning
Try using the web application framework Flask
Web application development in Go language_Hands-on day 1
About Cloud run + Firebase development [Web application development]
I made a WEB application with Django
How to build an application from the cloud using the Django web framework
First Django development
Web App Development Practice: Create a Shift Creation Page with Django! (Authentication system processing)
100 language processing knock-92 (using Gensim): application to analogy data
Build a Django development environment using pyenv-virtualenv on Mac
Web application made with Python3.4 + Django (Part.1 Environment construction)
Tech-Circle Let's start application development using machine learning (self-study)
Prepare Django development environment using homebrew on MacOSX Mavericks (10.9)
Development digest with Django
Django python web framework
Try using Django templates.html
[Memo] Django development environment
Try using the Python web framework Django (2) --Look at setting.py