Create Django Project

Saprunov Vadim·2022년 6월 5일
0

Django

목록 보기
1/2
post-thumbnail

Initializing the Virtual Environment

  1. Create a Project folder
  2. Create Virtual Environment(inside the project folder):
python3 -m venv /path-to-venv-folder

  1. Then you have to activate the venv
    for linux
    source /path-to-venv-folder/bin/activate
    for windows
    . path-to-venv-folder/Scripts/activate
    If everything was done correctly, you should be able to see the next message in the git bash terminal:

Downloading Libraries

pip install Django

After this step, you should have the Django library in your lib folder in Virtual Environment.

Creating Django Project

To create a Django project in git bash, write this:
Make sure to do this outside of your venv folder!

django-admin startproject projectname

This command will create a Django project directory.

Basic files explanation:

  1. mysite dir is a root dir of the project.
  2. manage.py is used to run the server, make migrations, etc.
    python manage.py runserver
  3. init.py tells python that this dir should be considered a Python package.
  4. settings.py config file for this project.
  5. urls.py URL declarations for this project.
  6. asgi.py and wsgi.py files are for deploying this project on the server.

Run Server

Before starting your server, you should make migrations.

python manage.py migrate


Then you can run the server!

python manage.py runserver

Finally, you should see the basic Django front page if everything was done correctly.

profile
Python, Django, AI, OCR.

0개의 댓글