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-
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.
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.
A Google search for "Django" found the second tutorial character in the list. I'm going to set up an environment to run Django.
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
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 a working folder in Explorer.
This time, let's say "C: django / poll".
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.
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>
(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 Django project. The project name is config.
(poll-HcNSSqhc) C:\django\poll>django-admin startproject config .
The following folders and files will be created.
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