Professional Documents
Culture Documents
Firstproject Django
Firstproject Django
--------------------------------------------
pip version to install necessary libraries upgrade python -m pip install --upgrade
pip
install django
check the version
Start Application
python maange.py startapp application name
testapp
__init__.py
views.py is a function is alway going to take the HTTP response
request --- response
write business logic in this file (function based , class based)
models.py
admin.py
app.py
test.py
folder - migrations empty folder
review:
django-admin startproject project-name
default files created
start project
start application
add this application to the project in settings.py file - project level
define view functions inside views.py
define url pattern for our view function inside urls.py
runserver
send request
http://127.0.0.1:8000/hello/
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^date/', views.hello_world_view),
url('morning/', views.good_morning_view),
url('afternoon/',views.good_afternoon_view),
url('evening/', views.good_evening_view),
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR=os.path.join(BASE_DIR,'templates') --- pointing to template
templates
python business and html related presentation logic
dict
def template_view(request):
dt=datetime.datetime.now()
my_dict={'date':dt}
return render(request,'testapp/results.html',context=my_dict)
or
def template_view(request):
dt=datetime.datetime.now()
return render(request,'testapp/results.html',{'date':dt})