0
我是Django的新手,無法弄清楚爲什麼表單不工作。看起來,表單提交後,即使URL被更改爲/82nsj/update
它仍然在視圖中的index
方法。Django表單提交url無法正常工作
查看
from business.models import Business, Token
from django.shortcuts import render
from business.forms import BusinessForm
def index(request, token):
try:
business = Business.objects.get(token__token=token)
except Token.DoesNotExist:
business = None
except Business.DoesNotExist:
business = None
form = BusinessForm(instance=business)
return render(request, 'business/index.html', {'form': form})
def update(request, token):
try:
business = Business.objects.get(token__token=token)
except Token.DoesNotExist:
business = None
except Business.DoesNotExist:
business = None
form = BusinessForm(request.POST, instance=business)
if form.is_valid():
form.save()
return render(request, 'business/index.html', {'form': form})
的url
url(r'^$', 'business.views.index', name='home'),
url(r'^business/(?P<token>\w+)/', 'business.views.index', name='business'),
url(r'^business/(?P<token>\w+)/update/', 'business.views.update', name='business_update'),
形式
self.helper = FormHelper(self)
self.helper.form_class = 'form-horizontal'
self.helper.form_action = 'update/'
self.helper.form_method = 'post'
self.helper.layout = Layout(
HTML("<p class='alert-info alert'>Please confirm your business contact information is updated and correct.</p>"),
Div(
'my',
'fields',
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary"),
),
css_class='row-fluid'
)
)
我知道這是行不通的,因爲我有breakpoi nts設置在我的index
和我的update
中,當我按下提交按鈕後,只有index
斷點正在到達。
我在做什麼錯誤是阻止update
方法運行表單提交?