0

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'
4

1 に答える 1

0

URLに名前を付ける必要があります

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 に答える