Reverse for 'media' with arguments '()' and keyword arguments '{}' not found

urls.py is

(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 is

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))

I am getting the below error "

NoReverseMatch at /member/when/
Reverse for 'media' with arguments '()' and keyword arguments '{}' not found."

in the following line in views.py

redirect_to = request.POST.get('next',
                reverse('media')
            )

template is

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

Answers


You need to name your urls

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

Or to avoid conflicting url names you can prefix with your app's name.

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

Obviously replace APP_NAME with the actual name of your app.

You can then update your template

{% url incident.views.media %}
# Changes to:
{% url 'media' %}

Need Your Help

MySQL PDO query syntax error with ? parameters

php mysql syntax parameters pdo

as a newbie, I've followed PHP MySQL tutorials advising the use of regular MySQL php functions. However, since I've been told that PDO is the better alternative, I've been converting my code to tha...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.