Creating project + basic file structure in Django
By Guru - May 11, 2021
Creating Project
I Assume that you have installed django on your computer, if not install
django from here.
Now create a Django project, open terminal/command prompt, go to
desired directory and type in following command
django-admin startproject myproject
Explanation :
- django-admin : command to call django
- startproject : command to tell django to start a new project
- project_name : project name of your choice, in case its my_project
Explanation :
- myproject : It's your base directory.
- myproject : It is root directory. It is inside your base direcory.
- __init__.py : An empty file that tells Python that this directory should be considered a Python package.
- asgi.py : An entry-point for ASGI-compatible web servers to serve your project.
- setting.py : This file contains all the information or data about your project.
- urls.py : This file contains all url patterns of your project and applications.
- wsgi.py : wsgi (web server gateway interface) is specified that how your web server communicate with web server.
- manage.py : A command line utility that let you interact with your application.
- db.sqlite3 : It's a database file.
- venv : It's a virtualenv directory.
Now start your server. Django provide you a local development server where
you can run your application.
Type in following to command to server
Note : make sure that you should be in your base directory where
manage.py file is present.
python manage.py runserver
You will get following message in your terminal/linux.
Note : For now ignore the waning alert in red.
Your server is succesfully started at
http://127.0.0.1:8000 or http://localhost:8000.
By default Django use port 8000
You can change is by this command.
python manage.py runerver 8080
Now go to your browser and you at above url you'll get.
Wrap up
Commands used :
django-admin startproject myproject
python manage.py runserver
python manage.py runserver
0 Comments