urls.py是
(r'^when/$', 'when'),
(r'^media/$', 'media'),
(r'^followup/$', 'followup'),
models.py
class Report(models.Model):
user = models.ForeignKey(User, null=False)
incident_number = models.CharField('Incident Number', max_length=100)
device_id = models.CharField('Device Id', max_length=100)
app_uuid = models.CharField('Unique App Id', max_length=100)
created_date_time = models.DateTimeField('Created')
manual_date_time = models.DateTimeField('Another time', null=True, blank=True)
sent_date_time = models.DateTimeField('Sent')
views.py是
def when(request):
if request.method == 'POST':
reportform = ReportForm(data=request.POST)
if reportform.is_valid():
log.debug("test:%s",reportform)
report = reportform.save(commit=False)
report.user = request.user
redirect_to = request.POST.get('next',
reverse('media')
)
return HttpResponseRedirect(media)
else:
pass
else:
reportform = ReportForm()
return render_to_response('incident/when.html',{
'newreport_menu': True,
'form': reportform,
},
context_instance=RequestContext(request))
我收到以下错误“
NoReverseMatch at /member/when/
Reverse for 'media' with arguments '()' and keyword arguments '{}' not found."
在views.py
中的以下行中redirect_to = request.POST.get('next',
reverse('media')
)
模板是
<form action="/member/when/" method="POST"> {% csrf_token %}
{{ form.manual_date_time }}
<p id=ir-nextbutn><a href="{% url incident.views.media %}">
{% include "buttons/next.html" %}</form>
AttributeError at /member/when/
'function' object has no attribute 'find'
答案 0 :(得分:0)
您需要为您的网址命名
url(r'^when/$', 'when', name='when'),
url(r'^media/$', 'media', name='media'),
url(r'^followup/$', 'followup', name='followup'),
或者为避免网址名称冲突,您可以使用应用名称作为前缀。
url(r'^when/$', 'when', name='APP_NAME_when'),
url(r'^media/$', 'media', name='APP_NAME_media'),
url(r'^followup/$', 'followup', name='APP_NAME_followup'),
显然,将APP_NAME替换为您应用的实际名称。
然后,您可以更新模板
{% url incident.views.media %}
# Changes to:
{% url 'media' %}