2013-01-15 111 views
0

顯示以下錯誤:找不到錯誤:找不到網頁(404)

Page not found (404) 
    Request Method: POST 
    Request URL: http://127.0.0.1:8000/events/toggle-attendance/%3E%3Cinput%20type= 
    Using the URLconf defined in std.urls, Django tried these URL patterns, in this order: 
    ^events/ ^tonight/$ [name='ev_tonight'] 
    ^events/ ^create/$ [name='ev_create'] 
    ^events/ ^toggle-attendance/$ [name='ev_toggle_attendance'] 
    ^admin/ 
    The current URL, events/toggle-attendance/><input type=, didn't match any of these. 

模板:

<form method="POST" class="toggle_attendance_form" action="{% url ev_toggle_attendance %}> 
<input type="hidden" name="event_id" value="{{ event.id }}" /> 
     {% if attending %} 
      <input class="attendance unattend" type="submit" value="Unattend" /> 
     {% else %} 
      <input class="attendance attend" type="submit" value="Attend" /> 
     {% endif %} 
    </form> 

查看:

高清toggle_attendance(請求): 嘗試: #將在post參數中承擔值 event_id = int(request.POST ['event_id'])

# couple of possible errors: no event_id in POST parameter or value can not casted as int 
except (KeyError, ValueError): 
    # raising http404: means it couldnt be found 
    raise Http404 
# getting the event where id= event_id 
event = get_object_or_404(Event, id=event_id) 
# 
attendance, created = Attendance.objects.get_or_create(user=request.user, 
    event=event) 
if created: 
    pass 
    # 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) 

# Check to see whether the next variable in the POST parameters 
next = request.POST.get('next', '') 
if not next: 
    next = reverse('ev_tonight') 
return HttpResponseRedirect(next) 
    toggle_attendance = login_required(toggle_attendance) 

網址:

URL模式=模式( '',

url(r'^tonight/$', views.tonight, name='ev_tonight'), 
url(r'^create/$', views.create, name='ev_create'), 
url(r'^toggle-attendance/$', views.toggle_attendance, name='ev_toggle_attendance'), 

可以請你幫我找到錯誤?

+0

看看服務器的錯誤日誌 - 它會告訴你什麼請求看起來像。這應該可以幫助你找到錯誤。 – Floris

+0

謝謝,它看起來像這樣。 [14/Jan/2013 22:21:27]「POST/events/toggle-attendance /%3E%3Cinput%20type = HTTP/ 1.1」404 2594 – user1802771

+0

也許如果您將請求更改爲「GET」爲了調試,您將在URL中精確地看到請求是如何形成的 – Floris

回答

1

找到了!您在

<form method="POST" 
class="toggle_attendance_form" action="{% url ev_toggle_attendance %}> 

缺少密切報價應

<form method="POST" 
class="toggle_attendance_form" action="{% url ev_toggle_attendance %}"> 

希望能夠解決它!

+0

非常感謝。它真的爲一個愚蠢的錯誤變得複雜... – user1802771