jupyter notebook
my django project
admin styles
app.js in static folder have absolute urls
cd f:/Dev/Python/menab_cms/env/Scripts
activate
cd f:/Dev/Python/menab_cms
python manage.py runserver
django web application framework designed as MTV(model template view)
- view contain all the business logics
- model works with the database structure
- template is work with layout of the application
DTL - django Template language
python -m venv env
cd env/Scripts
run activate.bat
pip install -r requirements.txt
pip freeze > requirements.txt
pip install django
pip install psycopg2
python -m pip install Pillow
pip install django-ckeditor
from django.urls import path
from . import views
urlpatterns = [
path('url_part', views.class_name.method_name, name=name),
]
Main urls.py sample
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('calc/' , include('app_name.urls'))
]
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render
class Calculator:
def index(request):
return HttpResponse('this is a sample index')
def home(request):
context = {'name': 'Girma'}
return render(request,'calc/index.html', context)
{{ name }} -- access values
{% block content %}
{% end block%}
{% extends file_name %} -- to insert current block to a parent file
- create a folder in the root directory of current project
- create folder with name of the app(optional)
- add your template folder name to TEMPLATES->DIRS of settings.py
- 'DIRS': [os.path.join(BASE_DIR, 'templates')],
- creat your html file
- create a folder into he root directory to store all of static files
STEPS
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
- django moves all the static files to assets folder when
python manage.py collect static command is run
- add {% load static %} to the template top section
- access file as {% static "--location and d file name in static folder--" %}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '',
'HOST': 'localhost',
'USER': '',
'PASSWORD': ''
}
}
python manage.py makemigrations --app_name--
python manage.py sqlmigrate --app_name-- --migration-name--
python manage.py migrate
- django-admin startproject projectName -- create new project
- django-admin startapp appName -- add new app to a project
- python manage.py runserver -- lounch a server for the current project
- python manage.py createsuperuser