Django version= 3.1
This is a django template for the ones just starting with django to follow to run their first app. This is a step by step guide to have their app successfully run to serve static and media files locally.
Steps:
1-Create a new folder for your django project2- Open your new folder in any IDE or code editor you like and run python #make sure you have installed django using pip install django
3- Open terminal and run django-admin startproject //name of project// to start a new django project
4- from termianl run python manage.py startapp //name of your first app// to have your first app in django.
to this point you have successfully started a django project with one app fun fact! you can check your django app's default UI by running python manage.py runserver and it should look ike this
Every project have some type of static and media files in it and there are some settings you need to cinfigue to tell django the location to follow
Base directory ( BASE_DIR ) is the root folder of your django project which contains the manage.py file and other django files of your project
you need to create static and media folders to have your files in there to be used in project.
After creating these folders, you need to tell django about these folders in the settings.py file of your project folder
add this after the static_URL line in settings.py file
Use this setting to confiure your Static files considering your foilder name is 'static'
Static_ROOT= os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'static')]
in this code you are telling django that this is the root folder for static and this is the base directory of static files
do this similar process for media files as wellUse this code to configure media files, condidering your media folder name is media
MEDIA_ROOT=os.path.join(BASE_DIR, 'media')
MEDIA_URL='/media/'
to have media files setup for this project
and configure this setting in settings.py of your project
In the template line in settings.py, in dir dictionary add [os.path.join(BASE_DIR, 'template')] as value and you have successfully configured the templates