Form and ModelForm
.order_by()
.order_by()pk ์ญ์์ผ๋ก ์ ๋ ฌ
articles = Article.objects.order_by('-pk')ModelForm
ModelForm ์ ์ํ๊ธฐ
forms.py
from django import forms
from .models import Article
class ArticleForm(forms.ModelForm):
title = forms.CharField(
max_length=100,
label='Title',
help_text='Your title must be no more than 100 characters in length',
widget=forms.TextInput(
attrs={
'class':'my_input',
'placeholder': "What's on your mind?"
}
)
)
content = forms.CharField(
label='Content',
help_text='Jot down random musings and thoughts',
widget=forms.Textarea(
attrs={
'row':5,
'col':50,
}
)
)
class Meta:
model = Article
# ๋ค ๋๋ ค๋ฐ์
fields = '__all__'View์์ ModelFrom ํ์ฉ
ModelFrom ํ์ฉview.py
request.resolver_match.url_name ์ผ๋ก ์กฐ๊ฑด์ ๋ฐ๋ฅธ ์ฒ๋ฆฌ
request.resolver_match.url_name ์ผ๋ก ์กฐ๊ฑด์ ๋ฐ๋ฅธ ์ฒ๋ฆฌform.html
๋ถ๊ธฐ์ ๊ธฐ์ค์
url_name์ด๋คpath๋ก ํ๋ฉด,url์ด ๋ฐ๋ ๋๋ง๋ค ๋ฐ๊ฟ์ค์ผ ํ๋ค!
loop or bootstrap4 ํ์ฉํ์ฌ ์ถ๋ ฅํ๊ธฐ
loop or bootstrap4 ํ์ฉํ์ฌ ์ถ๋ ฅํ๊ธฐform.html
shell ๋ค์ด๊ฐ๊ธฐ
shell
ptag ๋ก ์ด๋ฃจ์ด์ง input๋ค์ ์งํฉ
table๋ก ์ด๋ฃจ์ด์ง input๋ค์ ์งํฉ
Looping over the formโs fields
If youโre using the same HTML for each of your form fields, you can reduce duplicate code by looping through each field in turn using a `
` loop:
Form rendering options
There are other output options though for the
/pairs:
{{ form.as_table }}will render them as table cells wrapped in tags{{ form.as_p }}will render them wrapped in `` tags{{ form.as_ul }}will render them wrapped in `` tags
Note that youโll have to provide the surrounding or elements yourself.
Hereโs the output of {{ form.as_p }} for our ContactForm instance:
Django Bootstrap ์ฌ์ฉํ๊ธฐ
Install
settings.py ์์
base.html์ bootstrap ์ฌ์ฉํ ๊ฑฐ๋ผ๊ณ ์ ์ธ
detail.html - bootstrap ์ ์ฉ๋๋ template๋ค์๋ ์ ์ธ
+
Git
ํน์ commit์ ๊ธฐ์ค์ผ๋ก ๋์๊ฐ๊ธฐ
test branch ๋ง๋ค๋ฉด์ ์ด๋ํ๊ธฐ
reference log ํ์ธ
์ด๋์ head ์๋์ง ํ์ธ
๋ค์ test branch๋ก ๋์๊ฐ๊ธฐ
Last updated
Was this helpful?