-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdjango.txt
More file actions
105 lines (58 loc) · 1.85 KB
/
django.txt
File metadata and controls
105 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
>>>>> Django <<<<<<<<
---------------------------------------
---------------------------------------
Keys: model, view, controller
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
>>>>>>>>>>>>> All Templates <<<<<<<<<<<<<<<<<<<<<
Python:
Templates Settings
//Templates Directory
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
//In settings.py file
'DIRS': [TEMPLATE_DIR]
'OR'
'DIRS': [BASE_DIR / 'templates']
---> ( Routes: urls.py file ) <---
//Sending the request to the right view (urls.py)
urlpatterns = [
path('admin/', admin.site.urls),
path('contact', views.contact, 'contact.html'),
path('book/<int:id>/', views.book_detail, name='book_detail'),
path('catalog/', include('catalog.urls')), re_path(r'^([0-9]+)/$', views.best),
]
---> ( Views ) <---
//Handling the request (views.py)
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse('Hello from Django!')
end
'OR'
def index(request):
my_dict = {"insert_me": "I am "}
return render(request, 'index.html', my_dict)
end
//templates/admin/base_site.html
{% extends "admin/base_site.html" %}
{% block branding %}
<img src="link/to/logo.png" alt="logo">
{{ block.super}}
{% endblock %}
---> ( Model ) <---
//Defining data models (models.py)
from django.db import models
class Team(models.Model):
team_name = models.CharField(max_length=40)
TEAM_LEVELS = (
('U09', 'Under 09s'),
('U10', 'Under 10s'),
('U11', 'Under 11s'),
)
team_level = models.CharField(max_length=3,
choices=TEAM_LEVELS, default='U11')
------------------------------------------------------
------------------------------------------------------