0

urls.py 是

(r'^when/$', 'when'),
    (r'^media/$', 'media'),
    (r'^followup/$', 'followup'),

模型.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'
4

1 回答 1

0

您需要命名您的网址

url(r'^when/$', 'when', name='when'),
url(r'^media/$', 'media', name='media'),
url(r'^followup/$', 'followup', name='followup'),

或者为了避免 url 名称冲突,您可以使用应用程序名称作为前缀。

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' %}
于 2013-05-02T14:22:57.517 回答