programming:django
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programming:django [2019/03/22 15:15] – clemix | programming:django [2019/04/24 16:22] (current) – [Static files] clemix | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | === Create a project === | + | ==== Create a project |
| <code bash> | <code bash> | ||
| django-admin startproject mysite | django-admin startproject mysite | ||
| Line 11: | Line 11: | ||
| </ | </ | ||
| - | === Launch the server === | + | ==== Launch the server |
| <code lang=bash> | <code lang=bash> | ||
| python manage.py runserver | python manage.py runserver | ||
| </ | </ | ||
| - | === Create a app inside a project === | + | ==== Create a app inside a project |
| Everything are apps. Each app has it's own subfolder. To create a app sceleton run | Everything are apps. Each app has it's own subfolder. To create a app sceleton run | ||
| <code lang=bash> | <code lang=bash> | ||
| Line 22: | Line 22: | ||
| </ | </ | ||
| - | === Register URL === | + | ==== Register URL ==== |
| In the polls/ | In the polls/ | ||
| <code python polls/ | <code python polls/ | ||
| Line 76: | Line 76: | ||
| </ | </ | ||
| - | === Templates === | + | ==== Templates |
| Templates are in the subfolder of the app. e.g. `mysite/ | Templates are in the subfolder of the app. e.g. `mysite/ | ||
| <code html polls/ | <code html polls/ | ||
| Line 111: | Line 111: | ||
| - | === Namespace url patterns === | + | ==== Namespace url patterns |
| Define the namespace by adding `app_name = < | Define the namespace by adding `app_name = < | ||
| <code python polls/ | <code python polls/ | ||
| Line 125: | Line 125: | ||
| </ | </ | ||
| - | === Static files === | + | ==== Static files ==== |
| Static files can be placed in the `static/` folder of each app. | Static files can be placed in the `static/` folder of each app. | ||
| Then refere to them inside the template like: | Then refere to them inside the template like: | ||
| Line 133: | Line 133: | ||
| </ | </ | ||
| - | === Mixed in for django_tables2 === | + | Run this command to store static files in proper folder: |
| + | <code bash> | ||
| + | python manage.py collectstatic | ||
| + | </ | ||
| + | ==== django_tables2 | ||
| + | === Mixedin | ||
| <code python> | <code python> | ||
| Line 153: | Line 158: | ||
| </ | </ | ||
| - | To make links of a value https:// | + | === Custom tables.Column === |
| + | <code python> | ||
| + | class AgeColumn(tables.Column): | ||
| + | def render(self, | ||
| + | diff = record.age() | ||
| + | color = '' | ||
| + | if (diff.seconds > 60 * 60 ): | ||
| + | color = ' | ||
| + | else: | ||
| + | color = ' | ||
| + | return format_html('< | ||
| + | |||
| + | class InstanceTable(tables.Table): | ||
| + | age = AgeColumn() | ||
| + | opt = tables.LinkColumn(' | ||
| + | class Meta: | ||
| + | model = Instance | ||
| + | template_name = ' | ||
| + | </ | ||
| + | |||
| + | To make links of a value https:// | ||
| ==== Update database ==== | ==== Update database ==== | ||
| Change the model file accordingly. [[https:// | Change the model file accordingly. [[https:// | ||
| Line 161: | Line 186: | ||
| python manage.py migrate | python manage.py migrate | ||
| </ | </ | ||
| + | |||
| + | ==== Bootstrap ==== | ||
| + | https:// | ||
programming/django.1553264134.txt.gz · Last modified: by clemix
