PyCharm Create Django Project
PyCharm is a powerful Python IDE that offers excellent support for the Django framework, especially in its Professional edition (PyCharm Pro).
Launch PyCharm and create a new project
- Open PyCharm and click 'New Project'
- Select 'Django' on the left
- Set the project location (Location)
- Configure the Python interpreter (creating a new virtual environment is recommended)

Configure project parameters
- Project name: Use a combination of lowercase letters and underscores (e.g., DjangoProject)
- Template language: Django is selected by default
- Front-end framework: Can be selected as needed (beginners may skip it)
- Enable Django admin: Can be checked

Wait for project initialization
PyCharm will automatically:
- Create a virtual environment
- Install the latest stable version of Django
- Generate the basic project structure
Project structure analysis
After creation, you will see the following main files and directories:

Project root directory
- manage.py: Django command-line tool
- Directory with the same name as the project(e.g., DjangoProject/): Contains the main project configuration
Project configuration directory
- init.py: Indicates this is a Python package
- settings.py: Project configuration file
- urls.py: URL routing configuration
- wsgi.py: WSGI server configuration
Other important files
- requirements.txt: Project dependency file (PyCharm may generate it automatically)
- venv/: Virtual environment directory (if you chose to create a virtual environment)
Run the Django development server
Run via PyCharm
- Click the run configuration dropdown in the top-right corner of PyCharm
- Select 'Configuration -> Edit'

- Make sure the Django server is configured
- Click the green Run button

Run via the command line
- Open PyCharm's terminal
-
Enter the command:
python3 manage.py runserver
After successful startup, the terminal shows the following information
:
- Visit http://127.0.0.1:8000 to view the default page:

Common Problem Solutions
- Port conflict: When using
python manage.py runserver 8080Specify a different port - Database not migrated: Must be executed on first run
python manage.py migrate
Create a Django app
Create a new app
Enter the following in PyCharm's terminal:
python3 manage.py startapp myapp

Add the app to settings.py 's INSTALLED_APPS:
INSTALLED_APPS = [
...
'myapp',
]

In the project urls.py , include the app's routes:
Example
from
django.
contrib
import
admin
from
django.
urls
import
path
urlpatterns
=
[
path
(
'admin/'
,
admin.
site
.
urls
)
,
path
(
'myapp/'
,
include
(
'myapp.urls'
)
)
,
]

App directory structure
- migrations/: Database migration files
- admin.py: Admin backend configuration
- apps.py: App configuration
- models.py: Data model definitions
- tests.py: Test code
- views.py: View functions
Configure URL routing under the myapp directory
Open myapp/models.py and define a model. For example:
Example
from
django.
db
import
models
class
Post
(
models.
Model
)
:
title
=
models.
CharField
(
max_length
=
200
)
content
=
models.
TextField
(
)
created_at
=
models.
DateTimeField
(
auto_now_add
=
True
)
def
str
(
self
)
:
return
self
.
title
After saving, run python manage.py makemigrations and python manage.py migrate to update the database.
** Create views and URLs:**
Define the view in myapp/views.py:
Example
from
django.
shortcuts
import
render
from
.
models
import
Post
def
post_list
(
request
)
:
posts
=
Post.
objects
.
all
(
)
return
render
(
request
,
'myapp/post_list.html'
,
{
'posts'
: posts
}
)
Configure the URL in myapp/urls.py (must be created manually):
Example
from
django.
urls
import
path
from
.
import
views
urlpatterns
=
[
path
(
''
,
views.
post_list
,
name
=
'post_list'
)
,
]
Create the DjangoProject/templates/myapp/ folder in the project root, then create post_list.html under that folder:
Example
Post List
Posts
-
{{ post.title }} - {{ post.created_at }}
-
No posts available.
{% for post in posts %}
{% empty %}
{% endfor %}
Make sure the TEMPLATES setting in settings.py includes the correct template directory:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
...
}
]