我在 Ubuntu 12.04 上使用 Django 1.4 和 Python 2.7。
我之前写过很多观点,但我有点困惑为什么我在这个上得到一个 404 错误。
网址.py:
url(r'^addNewClient/', 'gateway_interface.views.add_new_client'),
视图.py
def add_new_client(request):
"""
.. function:: add_new_client()
Provide a form for entering new client information
:param request: Django Request object
"""
## Create a logging object
path = os.path.join(os.path.dirname(__file__), 'logs/')
filename = '{0}addNewClient.log'.format(path)
logfile = open(filename, 'a')
now = datetime.datetime.now()
logfile.write('\n --------------------- {0}\n'.format(now))
try:
form = addClientInfo()
except:
output = "Handle Error: Cannot create a valid form"
logfile.write('{0}\n'.format(output))
logfile.write('{0}\n\n'.format(traceback.format_exc()))
logfile.close()
return HttpResponse(output)
try:
data = {}
data.update(csrf(request))
data.update({ 'form' : form })
except:
output = "Handle Error: Cannot generate CSRF token"
logfile.write('{0}\n'.format(output))
logfile.write('{0}\n\n'.format(traceback.format_exc()))
logfile.close()
return HttpResponse(output)
return render_to_response("addNewClientInfo.html", data)
表格.py
class addClientInfo(forms.Form):
"""
.. class:: addClientInfo
Create a form to enter new client info
"""
my_gateway_choices = tuple(gateway_proper_names.items())
# Create the post fields
tkz_client_name = forms.CharField(max_length = 50, required = True)
tkz_gateway = forms.ChoiceField(widget = forms.Select(), choices = my_gateway_choices, required = True)
tkz_gateway_api_id = forms.CharField(max_length = 50, required = True)
tkz_gateway_trans_key = forms.CharField(max_length = 50, required = True)
tkz_ys_api_id = forms.CharField(max_length = 50, required = True)
tkz_ys_trans_key = forms.CharField(max_length = 50, required = True)
有什么想法吗?
编辑1:
我应该提到我没有在错误日志中收到任何信息。.html 文件与我的所有其他模板一起存在......在同一个地方。