[PYTHON] Django starting from scratch (part: 1)


I'm working and there are a lot of things related to Django's libraries that I wanted to touch once


--Understanding the flow of application creation --Understand the libraries you can use


Creating your first Django app, part 1|Django documentation| Django


Start of django project

django-admin startproject mysite

Running the above code will create a project for django with the name mysite.

Contents of the project

The project structure is as follows.


--The guy who does various operations on the manage.py project --The inner mysite is a Python package --mysite / settings.py: Django project configuration file --mysite / urls.py: Django project URL declaration (like a controller?) --mysite / asgi.py: Entry point for the ASGI compatible web server that provides the project Entry point: The place where the execution of a program or subroutine starts when the program is executed (something like main.py).

--mysite / wsgi.py: Web server

Development server

If you execute the above code in the directory where manage.py is located, that is, the outer mysite, it will start up.

python manage.py runserver

If you want to change the server port, do as follows.

python manage.py runserver 8080

polls application

Ready to create

Execute the following command in the same hierarchy as manage.py

python manage.py startapp polls

A directory called polls is automatically generated. The contents are as follows.


The polls part is optional. The start app is important.

Add urls.py and create urls.py and views.py.


from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")


from django.urls import path

from . import views

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

Root URLconf


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

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),

--Added urlconf in the list of urlpatterns. --In django, when you encounter include (), it cuts up to the url that matches up to that point. --Pass the rest of the string to the included URLconf for the next process. For http: // polls / hogehoge / http: // polls / (cut off to this point), hogehoge / (pass this to polls.urls)

Confirmation of execution result

Check the execution result with the following command

$ python manage.py runserver

Go to http: // localhost: 8000 / polls / and Success if "Hello, world. You`re at the polls index." Is displayed

Recommended Posts

Django starting from scratch (part: 2)
Django starting from scratch (part: 1)
Django memo # 1 from scratch
Build a bulletin board app from scratch with Django. (Part 2)
Build a bulletin board app from scratch with Django. (Part 3)
Let Code Day75 starting from scratch "15.3 Sum"
Django begins part 1
Django begins part 4
Business efficiency starting from scratch with Python
Let Code Day 29 "46. Permutations" starting from scratch
"Deep Learning from scratch" Self-study memo (Part 12) Deep learning
Let Code Day 27 "101. Symmetric Tree" starting from scratch
Microservices with GCP on RoR starting from scratch
Let Code Day 41 "394. Decode String" starting from scratch
Let Code Day 25 "70. Climbing Stairs" starting from scratch
Let Code Day69 starting from scratch "279. Perfect Squares"
Let Code Day 34 starting from scratch "118. Pascal's Triangle"
Let Code Day85 starting from scratch "6. ZigZag Conversion"
Let Code Day20 starting from scratch "134. Gas Station"
Machine learning starting from scratch (machine learning learned with Kaggle)
Let Code Day 88 "139. Word Break" starting from scratch
Let Code Day 28 "198. House Robber" starting from scratch
Let Code Day 39 "494. Target Sum" starting from scratch
Let Code Day 36 "155. Min Stack" starting from scratch
Let Code Day 17 "169. Majority Element" starting from scratch
Let Code Day 33 "1. Two Sum" starting from scratch
Deep Learning from scratch
Keras starting from nothing
Building Linux From Scratch 10.0
Let Code Day 23 "226. Invert Binary Tree" starting from scratch
Let Code Day8 starting from scratch "1302. Deepest Leaves Sum"
Let Code Day 22 starting from scratch "141. Linked List Cycle"
I set up Django from scratch (Vagrant, Centos, Python3)
Let Code Day 30 starting from scratch "234. Palindrome Linked List"
Let Code Day 32 "437. Path Sum III" starting from scratch
Let Code Day68 starting from scratch "709. To Lower Case"
Let Code Day 26 starting from scratch "94. Binary Tree Inorder Traversal"
Let Code Day 46 starting from scratch "406. Queue Reconstruction by Height"
ChIP-seq analysis starting from zero
Let Code Day 31 starting from scratch "581. Shortest Unsorted Continuous Subarray"
Deploy Django + React from scratch to GKE (1) Backend development --Nginx + Django
Deploy Django + React from scratch to GKE: Table of Contents
Keras 5th starting from nothing
Use django model from interpreter
Keras starting from nothing 1st
Let Code Day 38 starting from scratch "208. Implement Trie (Prefix Tree)"
Let Code Day3 starting from scratch "1313. Decompress Run-Length Encoded List"
Keras 4th starting from nothing
Template registration from Django Bootstrap
Keras starting from nothing 2nd
I tried to implement Perceptron Part 1 [Deep Learning from scratch]
Keras starting from nothing 3rd
Let Code Day 65 "560. Subarray Sum Equals K" starting from scratch
Let Code Day4 starting from scratch "938. Range Sum of BST"
Deploy Django + React from scratch to GKE (3) Create a GCP project
Lua version Deep Learning from scratch Part 6 [Neural network inference processing]
Re: Life in Heroku starting from scratch with Flask ~ PhantomJS to Heroku ~
Let Code Day 77 starting from scratch "1502. Can Make Arithmetic Progression From Sequence"
Let Code Day 76 starting from scratch "3. Longest Substring Without Repeating Characters"
Test Driven Development with Django Part 3
Test Driven Development with Django Part 4