튜토리얼 (https://godjango.com/29-crispy-forms/)에서 파삭 파삭 한 양식을 작성했으며 urls.py에 URL을 정의해야한다는 오류가 나타납니다. . 나는 여전히 하나 이상의 쟁점이있을 수 있다는 감을 잡는다. 나는이 작업을 계속하려고 노력 중이며 연구를 계속할 것이지만, 장고와 파이썬이 그렇게 어려움을 겪고있다. 기쁜 마음으로받은 모든 안내.장고 싱싱 양식 - home.html에서 양식 만들기 및 오류 받기
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field
from crispy_forms.bootstrap import (
PrependedText, PrependedAppendedText, FormActions)
class SimpleForm(forms.Form):
username = forms.CharField(label="Username", required=True)
password = forms.CharField(
label="Password", required=True, widget=forms.PasswordInput)
remember = forms.BooleanField(label="Remember Me?")
helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('login', 'login', css_class='btn-primary'))
class CartForm(forms.Form):
item = forms.CharField()
quantity = forms.IntegerField(label="Qty")
price = forms.DecimalField()
helper = FormHelper()
helper.form_method = 'POST'
helper.layout = Layout(
'item',
PrependedText('quantity', '#'),
PrependedAppendedText('price', '$', '.00'),
FormActions(Submit('login', 'login', css_class='btn-primary'))
)
class CreditCardForm(forms.Form):
fullname = forms.CharField(label="Full Name", required=True)
card_number = forms.CharField(label="Card", required=True, max_length=16)
expire = forms.DateField(label="Expire Date", input_formats=['%m/%y'])
ccv = forms.IntegerField(label="ccv")
notes = forms.CharField(label="Order Notes", widget=forms.Textarea())
helper = FormHelper()
helper.form_method = 'POST'
helper.form_class = 'form-horizontal'
helper.label_class = 'col-sm-2'
helper.field_class = 'col-sm-4'
helper.layout = Layout(
Field('fullname', css_class='input-sm'),
Field('card_number', css_class='input-sm'),
Field('expire', css_class='input-sm'),
Field('ccv', css_class='input-sm'),
Field('notes', rows=3),
FormActions(Submit('purchase', 'purchase', css_class='btn-primary'))
)
views.py
from django.views.generic import FormView
from forms import SimpleForm, CreditCardForm, CartForm
class MainView(FormView):
template_name = "pages/home.html"
form_class = SimpleForm
forms.py : 참고로
Failed lookup for key [form] in "[{'True': True, 'False': False, 'None': None}, {}, {}, {'view': <django.views.generic.base.TemplateView object at 0x10faa03c8>, 'home_url': '/'}]"
여기에 파일입니다 : 여기
오류 발생urls.py
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^page/$', TemplateView.as_view(template_name='pages/page.html'), name='page'),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, admin.site.urls),
# User management
url(r'^users/', include('base_django_template.users.urls', namespace='users')),
url(r'^accounts/', include('allauth.urls')),
# Your stuff: custom urls includes go here
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit
# these url in browser to see how these error pages look like.
urlpatterns += [
url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception('Bad Request!')}),
url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception('Permission Denied')}),
url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception('Page not Found')}),
url(r'^500/$', default_views.server_error),
]
if 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
및 home.html을 내가 가진
<section id="contact" class="contact">
<div class="container">
<div class="row">
{% crispy form %}
</div>
</div>
</section>
섹션은 home.html을 상단에 {% 부하 %를 crispy_forms_tags}.
답변이 작동하는지 알려주세요. –
그랬습니다 - 나는 당신의 답을 올바른 것으로 표시했습니다. 이제 완료하려면 클래스 기반보기로 리디렉션을 추가해야합니다. – Steve
Ahh thanks.you는 뷰 클래스에서 success_url = "/ success /"을 사용할 수 있습니다. –