What is a dog? Volume of GET request and query parameters

Receive URL query parameters

Hello one! This is Ponta, a Shiba Inu. When I was playing ball in the park today, I was very embarrassed to receive the ball on my face.

Now, as the title suggests, I would like to receive and display URL query parameters. http://example.com/wan/?type=shiba&name=Ponta If it is written, it will be received as data of {type: shiba}, {name: Ponta} (combination of {key: value}).

(venv_dog) Ponta@shiba_app # cat wan/views.py
from django.http import HttpResponse

def index(request):
    if 'name' in request.GET:
        name = request.GET['name']
        res = "Name is" + name + "is."
    else:
        res = ""
    if 'dogtype' in request.GET:
        dogtype = request.GET['dogtype']
        res = res + "The breed of dog" + dogtype + "is."
    if len(res) == 0:
        res = "Wan! name(name)And dog breed(dogtype)Please tell me!"
    
    return HttpResponse(res)

(venv_dog) Ponta@shiba_app # 

Did you do it well?

When there are parameters スクリーンショット 2020-08-24 22.50.08.png

When not スクリーンショット 2020-08-24 22.52.06.png

One that worked! See you dear! Bye bye!

Recommended Posts

What is a dog? Volume of GET request and query parameters
What is a dog? Django installation volume
What is a dog? Python installation volume
What is a dog? Django--Get Name and Date from URL Volume
What is a dog? Challenge Django templates! Volume
What is a dog? Django--Create a custom user model
What is a dog? Django--Create a custom user model 2
What is equal repayment of principal and interest and equal repayment of principal and interest?
What is a distribution?
What is a dog? Django App Creation Start Volume--startapp
What is a terminal?
What is a dog? Django--Volume of using values obtained from URLs in class-based views
What is a hacker?
What is a dog? Django App Creation Start Volume--startproject
Basics of Python learning ~ What is a string literal? ~
What is a pointer?
What is a recommend engine? Summary of the types
What is a dog? Django--Getting Started with Form for the First Time POST Transmission Volume
Get query parameters for Flask GET
What is a decision tree?
[Python] Python and security-① What is Python?
What is a super user?
What is a system call
[Definition] What is a framework?
What is a callback function?
What is a python map?
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
Get a list of camera parameters that can be set with cv2.VideoCapture and make it a dictionary type
[Python] What is a zip function?
[Python] What is a with statement?
What is a lexical scope / dynamic scope?
What kind of Kernel is this Kernel?
Get a Boolean in Flask's request
For Windows: Get a list of directories and files under a specific directory.
What is the XX file at the root of a popular Python project?
[Introduction to Python] What is the difference between a list and a tuple?