Note that there are some explanatory texts on larger screens.

plurals
  1. POReverse for '''' with arguments '()' and keyword arguments '{}' not found
    text
    copied!<p>Please help. I'm getting this error: </p> <blockquote> <p>Reverse for ''ev_toggle_attendance'' with arguments '()' and keyword arguments '{}' not found.</p> </blockquote> <p>Here's my html file:</p> <pre><code> {% extends "base.html" %} {% block title %}Tonight - {{ block.super }}{% endblock %} {% block main_content %} &lt;a href ="{% url ev_create %}"&gt;Create an Event&lt;/a&gt; {% if events %} {% for event, attending in events %} &lt;p&gt;{{event.creator.username}}: {{event.description}}&lt;/p&gt; {% if attending %} &lt;p&gt; You are attending this event.&lt;/p&gt; {% else %} &lt;p&gt; You are not attending this event. &lt;/p&gt; {% endif %} &lt;form method="POST" class="toggle_attendance_form" action="{% url ev_toggle_attendance %}"&gt; &lt;input type="hidden" name="event_id" value="{{event.id}}"/&gt; {% if attending %} &lt;input class="attendance unattend" type="submit" value="Unattend"/&gt; {% else %} &lt;input class="attendance attend" type="submit" value="Attend"/&gt; {% endif %} &lt;/form&gt; {% endfor %} {% else %} &lt;p&gt;No events for today.&lt;/p&gt; {% endif %} {% endblock %} </code></pre> <p>It says the error is here: </p> <pre><code>&lt;form method="POST" class="toggle_attendance_form" action="{% url ev_toggle_attendance %}"&gt; </code></pre> <p>urls.py file:</p> <pre><code>from django.conf.urls import patterns, include, url from events import views urlpatterns = patterns('', url(r'^create/$', views.create, name='ev_create'), url(r'^tonight/$', views.tonight, name='ev_tonight'), #ev_tonight is the name of the url pattern; good for templates url(r'^toggle-attendance/$', views.toggle_attendance, name='ev_toggle_attendance'), ) </code></pre> <p>views.py snippet:</p> <pre><code>from events.models import Event, Attendance from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from events.forms import EventForm from dateutil.parser import parse from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect, Http404 from django.contrib import messages from django.contrib.auth.decorators import login_required # Create your views here. def tonight(request): events = Event.objects.today().filter(latest=True) #loop thru all the events and check to see if the currently logged in user is attending the event attending=[] for event in events: #for every event in all the events, query for an attendance objects that matches event for the user try: Attendance.objects.get(event=event, user=request.user) attending.append(True) except Attendance.DoesNotExist: #if can't find it attending.append(False) context = { 'events':zip(events, attending), #zip function to merge event and attending } return render_to_response('events/tonight.html', context, context_instance=RequestContext(request) ) #context_instance: context processors: things that get run on request and add context to it; does things like adding the user variable to the template. def create(request): form = EventForm(request.POST or None) if form.is_valid():#check if there's data as well as within the 340 characters limit event = form.save(commit = False) #won't save to database coz creator isn't yet known event.creator = request.user guessed_date = None for word in event.description.split(): #split on every space - guess the date based on things inside the description try: guessed_date = parse(word) break#if found, break except ValueError: continue event.start_date = guessed_date event.save() #saves to the database messages.add_message(request, messages.INFO, 'Your event was posted.') #redirect user to another url if 'next' in request.POST: #if somewhere in the post value, there's a next next = request.POST['next'] else: next = reverse('ev_tonight') #otherwise, next will be the url with ev_tonight return HttpResponseRedirect(next) #if the form isn't valid return render_to_response( 'events/create.html', {'form':form}, context_instance = RequestContext(request)) create = login_required(create) #ensuring that the user logged in or can do @login_required before the create model(python &gt;= 2.4) def toggle_attendance(request): try: event_id = int(request.POST['event_id'])#assuming there are values in the post parameter; cast into an it except (KeyError, ValueError): #raise an exception when: no event id in the post parameter or a value that could not be cast to an int raise Http404 event = get_object_or_404(Event, id=event_id) attendance, created = Attendance.objects.get_or_create(user=request.user, event=event)#calling for the user that is logged in and for the event that has already been queried for if created: messages.add_message(request, messages.INFO, 'You are now attending "%s"' %event) else: attendance.delete() messages.add_message(request, messages.INFO, 'You are no longer attending "%s"' %event) #checking to see if there's a next variable in the post parameter; if it isn't assign an empty string next=request.POST.get('next', '') if not next: #if it's the empty string next=reverse('ev_tonight') return HttpResponseRedirect(next) toggle_attendance = login_required(toggle_attendance) </code></pre> <p>main url file:</p> <pre><code>from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^events/', include('events.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), ) </code></pre> <p>Any assistance that can be rendered is much appreciated.</p> <p>thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload