Skip to content

django template for beginners to use to run their first django app with standard configurations to host static and media files locally

License

Notifications You must be signed in to change notification settings

aftabahmaddev/django_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Read me for this django template

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:

starting project and first app

1-Create a new folder for your django project

2- 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 runserver

Static, Media files setting

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 base dir

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

Configuring Static files

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 static files

Configuring Media files

do this similar process for media files as well

Use this code to configure media files, condidering your media folder name is media

MEDIA_ROOT=os.path.join(BASE_DIR, 'media')
MEDIA_URL='/media/' media files to have media files setup for this project

Configuring Templates

In order to configure templates in django, add a folder in base dir named template

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

templates

About

django template for beginners to use to run their first django app with standard configurations to host static and media files locally

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published