简体   繁体   English

我在处理来自Django的404错误消息时遇到了麻烦。 它说“找不到与查询匹配的位置”

[英]I am having troubles with a 404-error message from Django. It says “No location found matching the query”

So I am taking the One Month Python course online and I am having some issues. 因此,我正在在线上学习一个月Python课程,但遇到了一些问题。 The thing is that my general expression (?P<pk>\\d+)/detail/$ does not seem to work hence the 404-message. 问题是我的一般表达式(?P<pk>\\d+)/detail/$似乎不起作用,因此出现了404消息。

Here is my code: main urls.py 这是我的代码:main urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns ('',
    # blah blah
    # blah blah blah
    # Blaaaahhh

    url(r'^admin/', include(admin.site.urls)),
    (r'', include('core.urls')),
)

core/urls.py 核心/ urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
import core.views as coreviews

urlpatterns = patterns ('',

    url(r'^$', coreviews.LandingView.as_view()),
    url(r'location/$', coreviews.LocationListView.as_view()),
    url(r'location/(?P<pk>\d+)/detail/$', coreviews.LocationDetailView.as_view()),

)

Views: 浏览次数:

from django.shortcuts import render
from django.views.generic.base import TemplateView
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
import core.models as coremodels
# Create your views here.

class LandingView(TemplateView):
    template_name = "base/index.html"


class LocationListView(ListView):
    model = coremodels.Location
    template_name = 'location/list.html'


class LocationDetailView(DetailView):
    model = coremodels.Location
    template_name = 'location/detail.html'
    context_object_name = 'location'

I have already created five locations using the Django admin site: https://gyazo.com/1db0b35fafdacb3d4991fbea3990ee61 我已经使用Django管理网站创建了五个位置: https : //gyazo.com/1db0b35fafdacb3d4991fbea3990ee61

Here is the actual error message: 这是实际的错误消息: 图片

The error message "No location found matching the query" suggests that the url pattern is correct, but there is no location with pk=1 in the database. 错误消息"No location found matching the query"表明网址格式正确,但是数据库中没有pk=1位置。 You probably deleted it. 您可能删除了它。

Try a different url eg /location/2/detail/ for a primary key that definitely exists. 尝试使用其他网址,例如/location/2/detail/ ,以获取肯定存在的主键。

You can find a primary key by doing something like Location.objects.first().id in the shell, or simply clicking on a location in the Django admin, and looking at the url. 您可以通过在外壳中执行类似于Location.objects.first().id来找到主键,或者只需单击Django admin中的某个位置,然后查看url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 404错误“找不到与查询匹配的博客条目” Django管理员问题 - 404 Error “No Blog entry found matching the query” Django admin issue Django 404:“没有找到与查询匹配的 object 实例” - Django 404: “No object instance found matching the query” 我在弦上遇到麻烦 - I am having troubles with a string Django。 在当前页面显示错误信息 - Django. Show error message on current page Django通用UpdateView在使用pk时返回404错误:“找不到匹配查询的用户” - Django generic UpdateView returns 404 error: "No user found matching the query" when using pk 找不到页面(404)Django。 定义网址 - Page not found (404) Django. Defining url addresses 将主键与 Django 中的 url 匹配。 当我尝试输入 url: (localhost:8000/detail/S1111111A/) 它总是显示不匹配错误 - Matching Primary key with url in Django. When I am trying to enter the url: (localhost:8000/detail/S1111111A/) it always shows a mismatch error 我正在尝试为django导入mysqldb。 &#39;my_config.h&#39;没有这样的文件或目录是我得到的错误 - I am trying to import mysqldb for django. 'my_config.h ' no such file or directory is the error that i am getting 我在 Django 搜索视图中遇到错误 - I am having an Error in Django Search Views 找不到页面 (404) - 找不到与查询匹配的可用性 - Page not found (404) - No availability found matching the query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM