I am very sorry for my personal matters. I started studying Django a month ago. I have been in Python for about 3 months. In any case, I am a big beginner. This is a small Django tutorial addressed to me at the time.
No. | title | |
---|---|---|
1 | To myself as a Django beginner (1)-Project app- | ☆ |
2 | To myself as a Django beginner (2)-What is MTV- | |
3 | To myself as a Django beginner (3)-Hello world!- | |
4 | To myself as a Django beginner (4)-Memo app creation- |
This tutorial is for those who have already learned Python to some extent, but have never created a web application or have never touched Django. The goal is to get a rough understanding of how Django works and make you feel that Django isn't scary and interesting. Therefore, we do not handle complicated contents. Please rest assured me a month ago.
--Development environment has been built -Here is an article about building a development environment that I have compiled. (Please read it) --Also, the site of here will be helpful. ――The author is Windows. (For Mac, please read as appropriate) --The virtual environment is already valid
Let's touch Django while actually moving our hands and see the basic operation.
First of all, execute the following command to create a project named myapp
.
C:\Users\User_name>django-admin startproject myapp
That's all you need to create a project. Let's check the contents. The file created in ~ \ User_name is as follows.
myapp/
manage.py ☆
myapp/
__init__.py
asgi.py
settings.py ☆
urls.py ☆
wsgi.py
The ☆ mark is used more frequently, so check it out.
Check the operation of the project here.
Go to the myapp
directory and run the following command:
C:\Users\User_name>cd myapp
C:\Users\User_name\myapp>python manage.py runserver
Then you can see the following output.
C:\Users\User_name\myapp>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 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.
May 17, 2020 - 10:01:28
Django version 2.2.12, using settings 'myapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Now that Django's development server has started, let's access http://127.0.0.1:8000/
with a browser. If a cute green rocket is flying, you win. Congratulations!!
I will create an application immediately. First, change to the myapp
directory.
C:\Users\User_name>cd myapp
Here we will create an app named ʻapp1`. Execute the following command.
C:\Users\User_name\myapp>python manage.py startapp app1
The file created in ~ \ User_name is as follows.
myapp/
manage.py
myapp/
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
app1 / <-Here! The app is ready! migrations/ init.py init.py admin.py apps.py models.py ☆ tests.py views.py ☆
☆ Mark is used very often. The files are above by default, but after this you can add ʻurls.py,
forms.py,
filters.py`, etc. as needed.
Next, we will inform the project that the app has been created.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles,
'app1', # add ]
With INSTALLED_APPS, you need to add your own apps and apps installed from outside as needed.
settings.py
is a settings file that not only adds the app, but also makes various settings such as databases and static files. For settings.py
, see Official Documents and here E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 81% AE% E4% B8% AD% E8% BA% AB% E3% 82% 92% E8% A7% A3% E8% AA% AC% E3% 80% 90% E3% 82% A4% E3% 83% A1% E3% 83% BC% E3% 82% B8% E3% 81% 8C% E5% A4% If you read A7% E5% 88% 87% E3% 81% A7% E3% 81% 99% E3% 80% 91), you will deepen your understanding.
That's all for the preparation. The flow up to this point is the same every time, so let's remember! As you get used to it, you will be able to do it even with your eyes closed. (Is a lie)
Next time will learn about MTV models!