[PYTHON] Procedure for creating an application with Django with Pycharm ~ Preparation ~

Introduction

This article will walk you through the preparation steps for creating an application with Django in Pycharm. It's just my procedure, so I think you can deepen your understanding by looking at other people's articles.

Create a new Pycharm project

  1. Select and click "File" from the menu bar on the upper left of Pycharm.
  2. Click "Create new project" at the top of the list.
  3. The location part says "untitled" by default, so delete that part and enter your favorite project name.
  4. Press Create at the bottom right and you will be asked if you want to create in a new window or in the current window, so choose the one you like. This completes the project creation.

Virtual environment construction

This time, we will build a virtual environment using Pipenv. Open the terminal at the bottom left of Pycharm.

Check if it is installed

First check if it is installed.

pipenv --version

If you see a number, it is installed.

When not installed

pip install pipenv

You can install it by entering it like this.

Add Django

pipenv install django

You can install the latest django by typing this way.

Virtual environment activation

pipenv shell

If you enter it like this, you can see that the part that was "(base)" in the leftmost part of the terminal has changed to the project name. This is the end of building the virtual environment.

Create Django projects and applications

First, let's create a project.

①django-admin startproject project name->A directory with the same name is created above the directory with the project name

②django-admin startproject project name. ->Can be created directly under a Pycharm project

As you can see by trying ①, it is recommended to add "." At the end as in ② because an extra directory will be created.

Next, we will create an application.

python manage.py startapp app name

Now you can create the app.

By the way

I will create it later, so I will write something that should be created in advance.

Pycharm project
      |
      |___django project directory
      |
      |___django application directory______templates
      |                              |
      |___manage.py                  |___urls.py
      |                              
      |___Other files

Create urls.py

There is no "urls.py" for the app, so create it in the app directory.

#Move to application directory
cd application directory name

#urls.Create py file
touch urls.py

That's it.

Creating templates

Create a templates directory to hold your HTML files.

#Move to the Django application directory
cd application directory name

#Creating a templates directory
mkdir templates

This is OK.

Pycharm project
      |
      |___django project directory
      |
      |___django application directory__templates directory
      |
      |___manage.py
      |
      |___Other files

The order can be out of order, so it's enough if it looks like this.

Create static directory

Create a "static" directory to store CSS files, JavaScript files, image files, etc.

#Move to application directory
cd application directory name

#Create static directory
mkdir static

#Move to static directory
cd static

#css directory creation
mkdir css

#javascript directory creation
mkdir javascrupt

#Create a directory to store images
mkdir img

This completes the preparation of the "static" directory.

Check if it can be executed

Let's check if it can be executed at the end.

#Create a migration file for version control of database configuration
python manage.py makemigrations 

#Change or undo changes to database configuration
python manage.py migrate

Let's type these two into the terminal.

#Run! !! !!
python manage.py runserver

If you can do this safely

http://127.0.0.1:8000/

Is displayed, so click it to jump to the browser. If the rocket is flying when the browser opens, it can be executed safely!

At the end

This time, I explained the procedure in the preparatory stage of creating an application using django in Pycharm. I'm glad if you can use it as a reference. I plan to write more articles in the future, so please take a look if you like. Continued ↓ ↓ settings.py

Recommended Posts

Procedure for creating an application with Django with Pycharm ~ Preparation ~
Commands for creating SNS with Django
[GCP] Procedure for creating a web application with Cloud Functions (Python + Flask)
Explanation of creating an application for displaying images and drawing with Python
Procedure for creating a LineBot made with Python
[Personal development] Story of creating an application for artists with SPA with Django REST Framework and Vue-Cli [DRF + Vue.js]
Create an API with Django
Creating an egg with python
Web application creation with Django
Rename an existing Django application
Getting Started with Django with PyCharm
(For beginners) Try creating a simple web API with Django
Load Django modules with an interpreter
Measure Django application coverage with Coverage.py
Deploy a Django application with Docker
Twitter posting application made with Django
Build a web application with Django
Create an environment for Django x Apache x mod_wsgi with Vagrant (Ubuntu 16.04)
Note: Send an email with Django
Create an application by classifying with Pygame
Creating an unknown Pokemon with StyleGAN2 [Part 1]
Creating an image splitting app with Tkinter
Browse an existing external database with Django
Note when creating an environment with python
Commands for creating a new django project
Creating an unknown Pokemon with StyleGAN2 [Part 2]
Creating a login screen with Django allauth
Create an update screen with Django Updateview
Application development using SQLite with Django (PTVS)
Crawl Follower for an account with Instagram
Preparation for scraping with python [Chocolate flavor]
I made a WEB application with Django
Creating an environment for OSS-DB Silver # 1_Create a Linux environment (CentOS7 virtual environment) with VirtualBox/Vagrant
Try creating a web application with Vue.js and Django (Mac)-(1) Environment construction, application creation
Media programming with Raspberry Pi (preparation for audio)
Building an Anaconda environment for Python with pyenv
Creating an interactive application using a topic model
Various commands for building an environment with Apache
Create a dashboard for Network devices with Django!
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
Create a one-file hello world application with django
Try building an environment for MayaPython with VisualStudioCode
Do an ambiguous search for mysql in Django
Beginners try to make an online battle Othello web application with Django + React + Bootstrap (1)
[Learning memo] How to make an application with Django ~ Until Hello World is displayed ~
[Learning memo] How to make an application with Django ~ From virtual environment to pushing to github ~
Volume of creating and publishing django-malice, a django application for causing HTTP 40X errors