Originally written on 2019-12-30. DEV's displayed publication date reflects this archive migration.
Django Learning Log rebuild project notes:
no reverse match error: normally there's a typo in your code, mainly on the
url tag, or url pattern error in url.py fileimport time:time.time()displays the time from 1970 in secondstimein strings:'Note - {}'.format(time.strftime('%b %d, %Y')), in month date, Year order, specifics check python doc > time.strftime()Url dispatcher and regex: you can use regex with
re_path('regex-in-here/', views.some_view_function),(?P\<name\>regex)is the same as<int: name>if it's integer. More to read on Django URL dispatcherMechanism of Django: models > urls > views > html > forms, and don't forget to add your new apps in settings, your models in
admin.site.register(ModelName),include('new_app.urls')-
forms.py: from Django import forms, from .models import ModelName, class FormName inherits(forms.ModelForm), sub-class
class Meta:capitalised, examples:
class TopicForm(forms.ModelForm): class Meta: model = Topic fields = ['text'] labels = {'text': ''} class EntryForm(forms.ModelForm): class Meta: model = Entry fields = ['title', 'text'] labels = {'title': 'Title', 'text': ''} widgets = {'text': forms.Textarea(attrs={'cols': 80})} -
filter in templates:
<!-- | is a template filter: a function modifies the value in a template variable --> <p>\{\{ entry.date_added | date:'M-d-y H:i' \}\}</p> <p>\{\{ entry.text | linebreaks \}\}</p> Jekyll won't render markdown with liquid tag like this {\%\%}
Top comments (0)