[PYTHON] What is a dog? Django App Creation Start Volume--startapp

Create an application

It's a Shiba Inu Ponta who is hot and hard to walk. Today, when I jumped into the river and took a bath while taking a walk, the owner hated me.

Now, I want to make a Django application.

(venv_dog) Ponta@shiba_app # tree
.
├── db.sqlite3
├── manage.py
└── shiba_app
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-38.pyc
    │   ├── settings.cpython-38.pyc
    │   ├── urls.cpython-38.pyc
    │   └── wsgi.cpython-38.pyc
    ├── asgi.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

2 directories, 11 files

I'll start here today. Well, there are more directories (\ _ \ _ pycache \ _ \ _) and files. I'm not sure, so I'm relieved for the time being. Create an application wan. The command is "python manage.py startalp (application name)" is.

(venv_dog) Ponta@shiba_app # python manage.py startapp wan
(venv_dog) Ponta@shiba_app # tree                         
.
├── db.sqlite3
├── manage.py
├── shiba_app
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── settings.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── wan
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

4 directories, 18 files

You now have a directory wan and a file in it. Next, let's display something. I will write the contents to be displayed in views.py, but before that, I will take a look at views.py.

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

# Create your views here.
(venv_dog) Ponta@shiba_app #

I wrote as follows.

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

def index(request):
    return HttpResponse("Wan!Shiba Inu Ponta")

(venv_dog) Ponta@shiba_app #

Now, let's set this function to be called by http access. You can call it directly from shiba_app / urls.py, but since I made an application called wan, I would like to call it from wan / urls.py.

(venv_dog) Ponta@shiba_app # cat shiba_app/urls.py 
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('wan/', include('wan.urls')),
]
(venv_dog) Ponta@shiba_app # cat wan/urls.py 
from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]
(venv_dog) Ponta@shiba_app # 

This is OK. http://127.0.0.1:8000/wan When you access, the second line of urlpatterns in shiba_app / urls.py,   path('wan/', include('wan.urls')) Transferred to the application wan directory wan, then In urlpatterns in wan / urls.py   path('', views.index, name='index') The function index described in views.py should be called.

Start the test server and try to access it

Let's do it. First, start the test server.

(venv_dog) Ponta@shiba_app # python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 23, 2020 - 08:59:15
Django version 3.1, using settings 'shiba_app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Go to http://127.0.0.1:8000/wan/ in your browser.

スクリーンショット 2020-08-23 18.15.44.png

One displayed properly! It's a success! By the way, in the terminal, it is displayed as follows,

[23/Aug/2020 09:15:36] "GET /wan/ HTTP/1.1" 200 20

HTTP status code 200 (OK) is returned. See you later! Bye bye!

Recommended Posts

What is a dog? Django App Creation Start Volume--startapp
What is a dog? Django App Creation Start Volume--startproject
What is a dog? Django installation volume
What is Django? .. ..
What is a dog? Python installation volume
What is a dog? Django--Create a custom user model
What is a dog? Django--Create a custom user model 2
What is a distribution?
What is a terminal?
What is a hacker?
What is a pointer?
Start a Django project
What is a dog? POST Sending Volume Using Django--forms.py
To myself as a Django beginner (2) --What is MTV?
What is a decision tree?
What is a Context Switch?
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?
[Python] What is a zip function?
[Python] What is a with statement?
Web App Development Practice: Create a Shift Creation Page with Django! (Shift creation page)
What is a lexical scope / dynamic scope?
What is a Convolutional Neural Network?
Implement a Django app on Hy
What is a dog? Volume of GET request and query parameters
What is a dog? Django--Get Name and Date from URL Volume
Web App Development Practice: Create a Shift Creation Page with Django! (Introduction)
Create a Todo app with Django ④ Implement folder and task creation functions
Django Tutorial (Blog App Creation) ⑤ --Article Creation Function
Django Tutorial (Blog App Creation) ④ --Unit Test
Django Tutorial (Blog App Creation) ① --Preparation, Top Page Creation
How to develop a cart app with Django
Start Django in a virtual environment with Pipenv
Django Tutorial (Blog App Creation) ③ --Article List Display
It's a Mac. What is the Linux command Linux?
Until you create a new app in Django
Django Tutorial (Blog App Creation) ⑦ --Front End Complete
Tell me what a conformal map is, Python!
I want to upload a Django app to heroku
Web App Development Practice: Create a Shift Creation Page with Django! (Authentication system processing)
What is a dog? Django--Volume of using values obtained from URLs in class-based views
Web App Development Practice: Create a Shift Creation Page with Django! (Experiment on admin page)
I made a command to wait for Django to start until the DB is ready