[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 0-

Introduction

Nice to meet you, everyone. From this time, I will publish the process of creating a voting (poll) application using Django as a memorandum. Since I am a beginner of Qiita, please understand that some parts may be difficult to read.

series

-[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 1-

The reason for writing this article

I decided to create a web app to improve my Python skills in my current job. I found an article that says "You can easily create a web application using Django!" And tried it immediately.

What is Django?

ファイル名

It's like a "web framework made in Python", that is, a package that contains the functions required to create a web application using Python. Specifically, it includes functions necessary for building a website, such as user authentication (sign-up, sign-in, sign-out), administrator screens, forms, and file uploads.

What do beginners start with?

ファイル名

A Google search for "Django" found the second tutorial character in the list. I'm going to set up an environment to run Django.

Create apps with Django tutorials

Creating your first Django app, part 1 ファイル名

Let's get started.

If you think, installation seems to be a separate page, so let's install from the link. Quick Install Guide

Django Pre-Installation Preparation

Python version check

Python version Python 3.8.6


Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:37:30) [MSC v.1927 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Create working folder

Create a working folder in Explorer.

This time, let's say "C: django / poll".

ファイル名

Create virtual environment

Install the virtual environment library with pip in the working folder.


C:\django\poll>pip install pipenv
Collecting pipenv
  Using cached pipenv-2020.8.13-py2.py3-none-any.whl (3.9 MB)
Collecting virtualenv-clone>=0.2.5
  Using cached virtualenv_clone-0.5.4-py2.py3-none-any.whl (6.6 kB)
Requirement already satisfied: pip>=18.0 in c:\python\lib\site-packages (from pipenv) (20.2.1)
Requirement already satisfied: setuptools>=36.2.1 in c:\python\lib\site-packages (from pipenv) (49.2.1)
Collecting virtualenv
  Using cached virtualenv-20.0.32-py2.py3-none-any.whl (4.9 MB)
Collecting certifi
  Using cached certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting six<2,>=1.9.0
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting distlib<1,>=0.3.1
  Using cached distlib-0.3.1-py2.py3-none-any.whl (335 kB)
Collecting filelock<4,>=3.0.0
  Using cached filelock-3.0.12-py3-none-any.whl (7.6 kB)
Collecting appdirs<2,>=1.4.3
  Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Installing collected packages: virtualenv-clone, six, distlib, filelock, appdirs, virtualenv, certifi, pipenv
Successfully installed appdirs-1.4.4 certifi-2020.6.20 distlib-0.3.1 filelock-3.0.12 pipenv-2020.8.13 six-1.15.0 virtualenv-20.0.32 virtualenv-clone-0.5.4
WARNING: You are using pip version 20.2.1; however, version 20.2.3 is available.
You should consider upgrading via the 'c:\python\python.exe -m pip install --upgrade pip' command.

C:\django\poll>

Start the virtual environment


C:\django\poll>pipenv shell
Creating a virtualenv for this project…
Pipfile: C:\django\poll\Pipfile
Using C:/python/python.exe (3.8.6) to create virtualenv…
[   =] Creating virtual environment...created virtual environment CPython3.8.6.final.0-32 in 1521ms
  creator CPython3Windows(dest=C:\Users\wmgoz\.virtualenvs\poll-HcNSSqhc, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\wmgoz\AppData\Local\pypa\virtualenv)
    added seed packages: pip==20.2.3, setuptools==50.3.0, wheel==0.35.1
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Successfully created virtual environment!
Virtualenv location: C:\Users\wmgoz\.virtualenvs\poll-HcNSSqhc
Creating a Pipfile for this project…
Launching subshell in virtual environment…
Microsoft Windows [Version 10.0.18362.1082]
(c) 2019 Microsoft Corporation. All rights reserved.

(poll-HcNSSqhc) C:\django\poll>

If the working directory is preceded by parentheses "()", the startup is complete.

Next, let's check the status of the virtual environment. The packages installed in the virtual environment are listed in the "Pipfile". If you want to develop with multiple people, you should share the Pipfile.

Pipfile



[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]

[requires]
python_version = "3.8"

At the time of creating the virtual environment, only Python 3.8 is installed. In the future, we will install packages in the virtual environment.

Django installation

Now let's install Django. Use "pipenv install ***" to pip install the package in a virtual environment.


(poll-HcNSSqhc) C:\django\poll>pipenv install django
Installing django…
Adding django to Pipfile's [packages]…
Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
           Building requirements...
Resolving dependencies...
Success!
Updated Pipfile.lock (a6086c)!
Installing dependencies from Pipfile.lock (a6086c)…
  ================================ 0/0 - 00:00:00

(poll-HcNSSqhc) C:\django\poll>

Installation of flake8 / autopep8


(poll-HcNSSqhc) C:\django\poll>pipenv install --dev flake8 autopep8
Installing flake8…
Adding flake8 to Pipfile's [dev-packages]…
Installation Succeeded
Installing autopep8…
Adding autopep8 to Pipfile's [dev-packages]…
Installation Succeeded
Pipfile.lock (a6086c) out of date, updating to (329161)…
Locking [dev-packages] dependencies…
 Locking...Building requirements...
Resolving dependencies...
Success!
Locking [packages] dependencies…
           Building requirements...
Resolving dependencies...
Success!
Updated Pipfile.lock (329161)!
Installing dependencies from Pipfile.lock (329161)…
  ================================ 0/0 - 00:00:00

(poll-HcNSSqhc) C:\django\poll>

Check the "Pip file".

Pipfile


[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "*"
autopep8 = "*"

[packages]
django = "*"

[requires]
python_version = "3.8"

"Django" "flake8" "autopep8" is installed. (* Means the latest version)

Create a project

Create a Django project. The project name is config.


(poll-HcNSSqhc) C:\django\poll>django-admin startproject config .

The following folders and files will be created. image.png

Launch the project

Launch your Django project.

(poll-HcNSSqhc) C:\django\poll>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.
October 04, 2020 - 12:21:42
Django version 3.1.2, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Open "http://172.0.0.1:8000/" in your browser and check the top page.

ファイル名

If a screen like this is displayed, setup is complete.

That's all for today. Thank you very much.

Recommended Posts

[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 7-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 1-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 2-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 0-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 5-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 6-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 4-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 3-
Django python web framework
Deploy a Python 3.6 / Django / Postgres web app on Azure
(Python) Try to develop a web application using Django
CTF beginner tried to build a problem server (web) [Problem]
Web scraping beginner with python
[Django3] Display a web page in Django3 + WSL + Python virtual environment
A liberal arts engineer tried knocking 100 language processes in Python 02
A python beginner tried to intern at an IT company
A liberal arts engineer tried knocking 100 language processes in Python 01
A liberal arts engineer tried knocking 100 language processes in Python 00
[Python / Django] Create a web API that responds in JSON format
I tried web scraping with python.
Build a web application with Django
Python beginner tried 100 language processing knock 2015 (05 ~ 09)
web coder tried excel in Python
When a Python beginner tried using Bottle, it worked unexpectedly easily.
Python beginner tried 100 language processing knock 2015 (00 ~ 04)
A beginner of machine learning tried to predict Arima Kinen with python
An introduction to self-made Python web applications for a sluggish third-year web engineer
A note where a Python beginner got stuck
[Beginner] Python web scraping using Google Colaboratory
I have a question! (Python, django) Easy
Daemonize a Python web app with Supervisor
I tried a functional language with Python
[Python] A quick web application with Bottle!
I tried to make a Web API
Use Django from a local Python script
Run a Python web application with Docker
Let's make a web framework with Python! (1)
I tried benchmarking a web application framework
Let's make a web framework with Python! (2)
I made a WEB application with Django
A python beginner tried to intern at an IT company [Day 2 chatbot survey]
A python beginner tried to intern at an IT company [Day 1 development process]
Go beginner tried to create a cloud native web application using Datastore / GAE
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I searched for the skills needed to become a web engineer in Python
Machine learning memo of a fledgling engineer Part 1
2-2. Input for becoming a WEB engineer (Linux basics)
How to open a web browser from python
Python web framework Django vs Pyramid vs Flask December 2015
I tried playing a typing game in Python
Start a simple Python web server with Docker
[Python] Build a Django development environment with Docker
[Memo] I tried a pivot table in Python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Create a web map using Python and GDAL
Steps to develop a web application in Python
[Python] Web development preparation (building a virtual environment)
I tried reading a CSV file using Python
Programming beginner Python3 engineer certification basic exam record
Launch a web server with Python and Flask
Machine learning memo of a fledgling engineer Part 2