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.
This time, we will build a virtual environment using Pipenv. Open the terminal at the bottom left of Pycharm.
First check if it is installed.
pipenv --version
If you see a number, it is installed.
pip install pipenv
You can install it by entering it like this.
pipenv install django
You can install the latest django by typing this way.
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.
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.
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
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.
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 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.
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!
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