-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
index.html
396 lines (353 loc) 路 12.7 KB
/
index.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
---
title: "Django integration"
date: 2021-04-29T16:00:58+02:00
draft: false
main_title: "Tailwind Elements Django integration"
subheading: ""
seo_title: "Tailwind Elements integration with Django - Free Examples & Tutorial"
description: "This article shows you how to integrate Django application with Tailwind Elements. Free download, AGPL license."
image: "https://tecdn.b-cdn.net/img/components-big.jpg"
url: "docs/standard/integrations/django-integration/"
menu:
integrations:
name: "Django"
---
<!--Prerequisites-->
<section id="section-prerequisites">
<!-- Title -->
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="prerequisites"
data-te-spy-item>
Prerequisites
</h2>
<!-- Description -->
<p class="mb-5">
Before starting the project make sure to install the following utilities:
</p>
<ul class="ml-4 list-disc">
<li>
<a
class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
href="https://nodejs.org/en/"
target="_blank"
>Node LTS</a
>
(14.x.x or higher recommended)
</li>
<li>
<a
class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
href="https://www.python.org/downloads/"
target="_blank"
>Python</a
>
</li>
<li>
<a
class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
href="https://pip.pypa.io/en/latest/installation/"
target="_blank"
>pip</a
>
package manager
</li>
<li>
Code editor. We recommend
<a
class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
href="https://code.visualstudio.com/"
target="_blank"
>VSCode</a
>
</li>
</ul>
</section>
<!--/Prerequisites-->
<hr class="my-5 dark:border-neutral-600" />
<!--Creating Django app-->
<section id="section-django-app">
<!-- Section title-->
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="laravel-application"
data-te-spy-item>
Creating a new Django application
</h2>
<!-- Description -->
<p class="mb-5">
Let's create a fresh Django application so that we can go through all the
steps together.
</p>
<h2 class="text-lg font-bold">Step 1</h2>
<p class="mb-5">Add Python virtual environment.</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal - Windows, Terminal - MacOS/Linux" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
mkdir my-project
cd my-project
py -3 -m venv venv
{{< /twsnippet/code >}}
{{< twsnippet/code lang="plaintext" type="terminal" >}}
mkdir my-project
cd my-project
python -3 -m venv venv
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 2</h2>
<p class="mb-5">
Now activate created environment. In case that you are working on Windows
and command is not working, try this:
<code>source ./venv/Scripts/activate</code>. After this you should see venv
catalogue and in your terminal will be visible <code>(venv)</code> badge.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal - Windows, Terminal - MacOS/Linux" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
venv/Scripts/activate
{{< /twsnippet/code >}}
{{< twsnippet/code lang="plaintext" type="terminal" >}}
. venv/bin/activate
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 3</h2>
<p class="mb-5">Install Django.</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
pip install django
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 4</h2>
<p class="mb-5">Create a project.</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
django-admin startproject mysite
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 5</h2>
<p class="mb-5">
Go to <code>settings.py</code> file in <code>mysite</code> folder and modify
section with paths for static files.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "settings.py" "" "mobile" >}}
{{< twsnippet/code active=true lang="python" >}}
TE_URL = 'node_modules/'
STATICFILES_DIRS = [
BASE_DIR / "static",
BASE_DIR.parent / "node_modules",
]
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
</section>
<!--/Creating Django app-->
<hr class="mb-5 dark:border-neutral-600" />
<!--Creating and configuring Tailwind & Tailwind Elements-->
<section id="section-tailwind">
<!-- Section title-->
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="tailwind"
data-te-spy-item>
Installing and configuring Tailwind CSS and Tailwind Elements
</h2>
<!-- Description -->
<h2 class="mt-5 text-lg font-bold">Step 1</h2>
<p class="mb-5">Install Tailwind CSS</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 2</h2>
<p class="mb-5">
Add the paths to all of your template files in your
<code>tailwind.config.js</code> file.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "tailwind.config.js" "" "mobile" >}}
{{< twsnippet/code active=true lang="JavaScript" >}}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{html,js}",
"./node_modules/tw-elements/dist/js/**/*.js",
],
theme: {
extend: {},
},
darkMode: "class",
plugins: [require("tw-elements/dist/plugin")],
};
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 3</h2>
<p class="mb-5">
Create an <code>static</code> folder in root directory and
<code>input.css</code> file. Then add the <code>@tailwind</code> directives
for each of Tailwind鈥檚 layers.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "input.css" "" "mobile" >}}
{{< twsnippet/code active=true lang="CSS" >}}
@tailwind base;
@tailwind components;
@tailwind utilities;
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 4</h2>
<p class="mb-5">
Start the Tailwind CLI build process. Run the CLI tool to scan your template
files for classes and build your CSS.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "Terminal" "" "mobile" >}}
{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
npx tailwindcss -i input.css -o static/output.css --watch
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 5</h2>
<p class="mb-5">
In root directory create a <code>pages</code> folder and place in there
<code>home.html</code> file. At the top (first line) should be found
<code>{% load static %}</code> phrase which allows to contains static files.
</p>
<p class="mb-5">
At the end of <code>head</code> section place link for Tailwind CSS file.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "home.html" "" "mobile" >}}
{{< twsnippet/code active=true lang="HTML" >}}
<link href="{% static 'output.css' %}" rel="stylesheet" />
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 6</h2>
<p class="mb-5">
In <code>home.html</code> file, at the end of <code>body</code> link script
for Tailwind Elements JS file.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "home.html" "" "mobile" >}}
{{< twsnippet/code active=true lang="HTML" >}}
<script
src="{% static 'tw-elements/dist/js/tw-elements.umd.min.js' %}"
type="text/javascript"></script>
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 7</h2>
<p class="mb-5">
Create <code>views.py</code> file in <code>mysite</code> folder and put in
there render for your first / home page.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "views.py" "" "mobile" >}}
{{< twsnippet/code active=true lang="python" >}}
from django.shortcuts import render
def home_view(request):
return render(request, "pages/home.html", {})
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 8</h2>
<p class="mb-5">
Then in <code>urls.py</code> file (located in <code>mysite</code> folder)
add import newly created <code>views.py</code> file and attach urls for
paths with static files.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "settings.py" "" "mobile" >}}
{{< twsnippet/code active=true lang="python" >}}
from django.conf import settings
...
from . import views
urlpatterns = [
path("", views.home_view),
path('admin/', admin.site.urls),
]
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.TE_URL,
document_root=settings.STATIC_ROOT)
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<h2 class="text-lg font-bold">Step 9</h2>
<p class="mb-5">
Alternatively at the end of <code>body</code> in
<code>home.html</code> include <code>script</code> tag with linking to
Tailwind Elements CDN.
</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "home.html" "" "mobile" >}}
{{< twsnippet/code active=true lang="HTML" >}}
<script src="https://cdn.jsdelivr.net/npm/tw-elements/dist/js/tw-elements.umd.min.js"></script>
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
</section>
<!--/Creating and configuring Tailwind & Tailwind Elements-->
<!--Initializing via JS-->
<section id="section-initializing-js">
<!-- Title -->
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="initializing-js"
data-te-spy-item>
Initializing via JS
</h2>
<!-- Description -->
<p class="mb-5">
By default all components have autoinit which means they are initialized by
data attributes. But if you want to make init by JavaScript - there is also
possibility to do that.
</p>
<h2 class="text-lg font-bold">Step 1</h2>
<p class="mb-5">Initialize components in <code>script</code> section.</p>
<div class="pb-4">
<!--prettier-ignore-->
{{< twsnippet/wrapper "home.html" "" "mobile" >}}
{{< twsnippet/code active=true lang="JavaScript" >}}
const myInput = new te.Input(document.getElementById("myDatepicker"));
const options = {
format: "dd-mm-yyyy",
};
const myDatepicker = new te.Datepicker(
document.getElementById("myDatepicker"),
options
);
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
</section>
<!--/Initializing via JS-->