找不到localhostweb页面
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了找不到localhostweb页面相关的知识,希望对你有一定的参考价值。
参考技术A 找不到localhostweb页面?答:找不到,不用着急。慢慢来,根据提示分体操作。找不到错误:找不到页面(404)
【中文标题】找不到错误:找不到页面(404)【英文标题】:can not find the error: Page not found (404) 【发布时间】:2012-12-29 04:04:50 【问题描述】:显示以下错误:
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>
查看:
def 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)
网址:
urlpatterns = patterns('',
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'),
)
你能帮我找出错误吗?
【问题讨论】:
查看服务器错误日志——它会告诉你请求是什么样的。这应该可以帮助您找到错误。 谢谢,它看起来像这样。 [14/Jan/2013 22:21:27]“POST /events/toggle-attendance/%3E%3Cinput%20type=HTTP/1.1”404 2594 也许如果您将请求更改为“GET”只是为了调试,您将在 URL 中看到请求的确切形成方式 %3E%3C 转换为><
- 知道它们为什么存在吗?
【参考方案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 %">
希望能解决!
【讨论】:
以上是关于找不到localhostweb页面的主要内容,如果未能解决你的问题,请参考以下文章
web页面找不到资源文件,报404,但是资源文件存在且路径没错
在 django 上运行的 Python Web 应用程序,cPanel 显示错误:找不到页面
无法运行 web api(网关)项目 - 找不到此 localhost 页面。未找到该网址的网页: