This repo is for tracking my Django learning path.
django-admin startproject PROJECT_NAME
python3 manage.py startapp APP_NAME
python3 manage.py runserver
python3 manage.py makemigrations APP_NAME
python3 manage.py migrate
- Create admin user:
python3 manage.py createsuperuser
- In
admin.py
file, register the models you have inmodels.py
file for each app as follows:
from .models import MODEL1, MODEL2
admin.site.register(MODEL1)
admin.site.register(MODEL2)
- Add the app name to
INSTALLED_APPS
list insettings.py
file. - Create
urls.py
file inside the new app and addurlpatterns
list containing the paths for your app. Also, add the variableapp_name = "APP_NAME"
to avoid name collisions. - In the main
urls.py
file for the project, include the urls for the new app. (e.gpath('APP_NAME/', include('APP_NAME.urls')),
) - If the app will have html content, create
templates/APP_NAME
folder to add the html files in it. - Also, you can create
static/APP_NAME
for static files such ascss
andjs
files and images.
In settings.py
file, change the DATABASES
variable to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_SCHEMA_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost',
'PORT': '3306',
}
}
git commit -m "Commit message" -m "Commit description line #1" -m "Commit description line #2"
git clone https://github.com/HackerSpaceJUST/<repo>
- Make a branch with a clear name for the feature you want to add:
git checkout -b BRANCH_NAME
. If the branch is already exist, then no need for the-b
in the command. - Modify your changes on your local device.
- When the modifications are finished:
git add .
to add all of the modified files. - Commit your work and write a clear message for your commit:
git commit -m "Your Message"
. - Push your work:
git push origin BRANCH_NAME
. - Go to
https://github.com/HackerSpaceJUST/<repo>
, add your commit as a pull request. - Go to Pull Requests and review your code.
- If your changes got approved then merge it to the main branch.
- Delete the used branch once the feature you're working on is finished.
**/__pycache__
**/migrations
.vscode
*.sqlite3
sudo apt-get install libmysqlclient-dev
(Formysql_config
)sudo apt-get install mysql-server
python3 -m pip install mysqlclient
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD';
from django.http import HttpResponseRedirect
from django.urls import reverse
return HttpResponseRedirect(reverse('APP_NAME:PATH_NAME'))
Alternatively:
from django.shortcuts import redirect
return redirect('APP_NAME:PATH_NAME')
<a href="{% url 'APP_NAME:PATH_NAME'%}">Some Text</a>
<form action="{% url 'APP_NAME:PATH_NAME'%}" method="post">
{% csrf_token %}
<input type="submit">
</form>
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>
{% extends "tasks/layout.html" %}
{% block body %}
HTML CONTENT
{% endblock %}