I want to make a web application with Django. However, it is difficult because the things that can be done are too wide and you have to get used to each concept.
This page will probably be a reminder of the Django concept while doing the Official Tutorial.
Django is one of the libraries for creating web applications in Python. The main features are:
The first thing is a library for creating web applications using the MVC framework. By the way, Jinja is the one that separates only the rendering motif, so the expression method around here is very similar to Jinja.
Unlike Flask, which is a similar (?) Routing library, it has a lot of functions such as database I / O and user authentication, so it is convenient when you want to quickly create a slightly elaborate application. However, since there are so many internal modules, Flask may be easier to understand if you only need simple functions (such as returning JSON).
It can also be used on Heroku (should).
As a quick understanding:
-** Project : A term that refers to the entire area of the app you are trying to create - Application **: Individual domain created inside the application
For a service like a CMS, for example, one service may include separate features such as Wiki, blog, and chat (whether it's design or not). It can be said that an application corresponds to an individual function in such a case.
Or, as another possibility, you could think of your application as a microservices implementation (although Django is basically an O / R mapper, so I think such a design wouldn't work very well). ..
Both projects and applications are represented in Django as Python modules and submodules, both of which can be separated into MVC chunks. Generally, in routing, the project corresponds to the /
(root) URL of the service, and each app hangs below it with a URL like / <app-name> / ...
. Often.
When starting to develop one service (project), first make a boilerplate for the project:
gwappa: myrepo$ django-admin startproject <project-name>
#Under the current directory<project-name>Directory is created,
#Basic files are written in it
Subsequent project operations are performed using the file manage.py
in the<project-name>
directory created by startproject
:
#Continuation of the above operation
gwappa: myrepo$ mv <project-name> src #It's okay to rename the outer directory
gwappa: myrepo$ cd src
gwappa: src$ python manage.py ... #Project operations
From manage.py
, use the command startapp
:
gwappa: src$ python manage.py startapp <app-name> #Unique name for each app
This will create a <app-name>
directory inside the project directory and place the boilerplate files in it.
Recommended Posts