Creating websites using Python and Django4 (I'm using Django5). The purpose of this repository is to learn front-end tools such as HTML, CSS and, Bootstrap combined with Django framework in python. The end goal for me is to create a website that will showcase my skills.
This course Django 4 and Python Full-Stack Developer Masterclass can be found on Udemy.
https://www.udemy.com/course/django-and-python-full-stack-developer-masterclass/?couponCode=LEADERSALE24B
This repository contains a devcontainer that is has Python 3.12 with a few vscode extensions I felt was useful (List of extensions can be found in the .devcontainer/devcontainer.json under customizations -> vscode -> extensions). The only prerequisite you would require to run this repository on your system would be to install docker and docker compose. After installing these, you should be able to open the repo in vscode and a prompt will pop up asking if you want to open the repo in the devcontainer. Click "Yes".
-
Assuming you are in the directory of choice to create your Django project, run the following command to create a project called
my_siteand go into that directory:django-admin startproject my_site
cd my_site/ -
Create a new app called my_app
python manage.py startapp my_app
-
Create a new file in the my_app folder called
urls.pycd my_app/ && touch urls.py && cd ..
-
You can create a new view in the
views.pyin my_app directory and create the url_pattern list similar to theviews.pyin my_site directory. -
Add the path to my_app urlpatherns in the
urls.pyin the my_site directory using the following syntax:path('my_app/', include('my_app.urls')),
-
Run the migration using the following command and you should see
OKon the terminal. Go toapps.pyin my_app directorypython manage.py migrate
-
You need to install the new app you have created
my_appon the django projectmy_site. Copy the class name and paste it under theINSTALLED_APPSlist in thesettings.pyfile in the following format:'my_app.apps.MyAppConfig',Now run the following command:
python manage.py makemigrations my_app
-
Once you are happy with the changes, you can apply the changes using the following command:
python manage.py migrate
Once this is done, you dont have to specify the template directory in the setting and django will search for the
temaplatesdirectory inmy_appdirectory. -
Now in the
my_appdirectory, you can create a folder calledtemplatesand inside this create another folder calledmy_app. This will house all the templates for the app. -
Finally you can run the server using the following command:
python manage.py runserver
- To create a super user, you need to be in the Django project directory you created and run the following command:
python manage.py createsuperuserYou would need to enter a username, password and an email_id (This is useful if you need to request a change in password)
- Sometime when you run the server, the content may not refresh. This can be due to two reason in my experience:
- You would need to restart the server for the changes to be updated.
- It can be a browser related caching issue, try using incognito mode.