[PYTHON] To myself as a Django beginner (1) --Create a project app--

at first

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.

** Tutorial list **

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-

Target

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.

** Premise **

--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 Django -Preparation- **

Let's touch Django while actually moving our hands and see the basic operation.

** Creating a project **

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!! django_server.PNG

** Creating an app **

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!

Recommended Posts

To myself as a Django beginner (1) --Create a project app--
To myself as a Django beginner (4) --Create a memo app--
To myself as a Django beginner (3)-Hello world! ---
To myself as a Django beginner (2) --What is MTV?
Shell to create django project
Deploy Django + React from scratch to GKE (3) Create a GCP project
How to develop a cart app with Django
How to create a Rest Api in Django
Until you create a new app in Django
I want to upload a Django app to heroku
Start a Django project
A memo to create a virtual environment (venv) before Django
Create a Todo app with Django REST Framework + Angular
I tried to create a table only with Django
Create a Todo app with the Django REST framework
Steps from installing Python 3 to creating a Django app
Create a Todo app with Django ③ Create a task list page
How to reference static files in a Django project
Create a Todo app with Django ⑤ Create a task editing function
Create a homepage with django
Create a Django login screen
Deploy django project to heroku
Create a shogi game record management app using Django 4 ~ Create View ~
Create a Todo app with Django ① Build an environment with Docker
A story about a beginner participating in a project by Django from team building to product release in 6 weeks
Create a shogi game record management app using Django 2-Database settings-
Create a temporary file with django as a zip file and return it
Web App Development Practice: Create a Shift Creation Page with Django! (Shift creation page)
Create a shogi game record management app using Django 6 ~ Template division ~
How to create a Conda package
Rails users try to create a simple blog engine with Django
How to create a virtual bridge
Create and deploy a Django (PTVS) app using Azure Table storage
Implement a Django app on Hy
How to deploy a Django app on heroku in just 5 minutes
5 Ways to Create a Python Chatbot
How to create a config file
Create a REST API to operate dynamodb with the Django REST Framework
Create a file uploader with Django
Create a LINE Bot in Django
Create a shogi game record management app using Django 3 ~ Django default management site settings ~
Create a Todo app with Django ④ Implement folder and task creation functions
I tried to create a linebot (implementation)
How to create a clone from Github
Create a new Python numerical calculation project
How to create a git clone folder
Create a model for your Django schedule
Create a simple GUI app in Python
Commands for creating a new django project
Create a GUI app with Python's Tkinter
Create a simple web app with flask
Create a Python-GUI app in Docker (PySimpleGUI)
Create your first app with Django startproject
How to create a repository from media
Script to create a Mac dictionary file
[Python] Introduce UIKit3 to your Django project
Go beginner tried to create a cloud native web application using Datastore / GAE
Create a Django project and application in a Python virtual environment and start the server
Create a web app that converts PDF to text using Flask and PyPDF2
A machine learning beginner tried to create a sheltie judgment AI in one day
[Python] List Comprehension Various ways to create a list