无法登录到Django admin 404错误 [英] Can't login into Django admin 404 error

查看:580
本文介绍了无法登录到Django admin 404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前无法在Django登录我的管理员,我收到一个404页面。

 找不到页面(404)
请求方法:GET
请求URL:http://127.0 .0.1:8000 / admin
没有匹配查询的博客条目

更新#3



最后更新: 12月17日上午10点



状态: / strong>仍然未解决,可以使用一些帮助




  • 我更新了此帖子顶部的错误消息,是的,错误信息很短。

  • 除了名为博客的应用程序之外,我还附带了实际项目的url.py。

  • 修正了迁移不同步

  • 终端不再有错误

  • 问题可能在模型中,views或urls.py



THE SUSPECTS



此代码段涉及startproject takehome



urls.py

 从django.conf .urls import pattern,include,url 
from django.contrib import admin

urlpatterns = patterns(
'',
url(r'^ admin /', include(admin.site.urls)),
url(r'^ markdown /',include(django_markdown.urls)),
url(r'^',include('blog.urls ')),

settings.py p>

  INSTALLED_APPS =(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'blog',
'django_markdown',

这三个代码片段与名为博客的应用程序相关联



Urls.py



来自django.conf.urls导入模式的

 ,url 
。导入视图

urlpatterns = patterns(
'',
url(r'^ $',views.BlogIndex.as_view(),name =list),
url(r'^(?P< slug> \S +)$',views.BlogDetail.as_view(),name =detailed),

Models.py

  from django.db import models 
from django.core.urlresolvers import reverse

#在这里创建你的模型。
class FullArticleQuerySet(models.QuerySet):
def published(self):
return self.filter(publish = True)

class FullArticle(models.Model) :
title = models.CharField(max_length = 150)
author = models.CharField(max_length = 150)
slug = models.SlugField(max_length = 200,unique = True)
pubDate = models.DateTimeField(auto_now_add = True)
已更新= models.DateTimeField(auto_now = True)
category = models.CharField(max_length = 150)
heroImage = models.CharField(max_length = 250,blank = True)
relatedImage = models.CharField(max_length = 250,blank = True)
body = models.TextField()
publish = models.BooleanField(default = True)
gameRank = models.CharField(max_length = 150,blank = True,null = True)

objects = FullArticleQuerySet.as_manager()

def __str __(self)
return self.title

def get_absolute_url(self):
return reverse(FullA rtty_detailed,kwargs = {slug:self.slug})

#def random(self):
#return self.get_queryset()。order_by('?')。 ('title','author','heroImage','body')。first()

class Meta:
verbose_name =Blog entry
verbose_name_plural =Blog条目
订购= [-pubDate]

views.py

  from django.views import generic 
from。导入模型

#在这里创建您的观点。
class BlogIndex(generic.ListView):
queryset = models.FullArticle.objects.published()
template_name =list.html
#paginate_by = 2

class BlogDetail(generic.DetailView):
model = models.FullArticle
template_name =detailed.html

#random = models.FullArticle.objects.order_by ('?')。values('title','author','heroImage','body')。first()


解决方案

更新:确定迁移问题已被移除。



更新2:ok,所以没有管理网址格式



你的在您的主要urls.py中导入博客网址?您可以通过模式r'^ admin /'和r'^ markdown /'作为博客条目匹配所有内容。
现在你的请求是/ admin,由于最后没有一个/(斜杠),而不是匹配第一个模式,它与最后一个匹配:r' ^(?P\S +)$。所以现在,它会使用一个名为admin的小插件来查找博客条目,找不到一个,因此返回404,非常清楚。 (下一次不要犹豫,在问题中包括:)



我还希望请求/ admin /导致一个管理页面,因为它会匹配r'^ admin /',因为尾随/



更好的做法是避免主要url和应用程序特定URL之间的冲突通过以下方式对您的博客进行子URL排序:

  url(r'^ blog /',include(' urls',namespace =blog)),

https://docs.djangoproject.com/en/dev/intro/tutorial03/#namespacing-url-names






更新前:
也许您尝试使订单字段具有唯一性,其中唯一的值。你尝试删除整个数据库并重建它吗?这将是我的第一个建议。



似乎在sqlite中有一些怪癖,我从来没有使用它。我也建议尝试使用比较成熟的东西,比如postgresql或者mysql。


I currently cannot log into my admin in Django, I get a 404 page.

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin
No Blog entry found matching the query

UPDATE #3

Last Updated: Dec 17, 10 AM

Status: Still unresolved, could use some help

  • I've updated the error message at the top of this post, and yes, the error message is short.
  • I've included the url.py for the actual project, in addition to the app called blog.
  • Fixed the migrations being out of sync
  • There is no longer an error in the Terminal
  • The problem might lie somewhere in models, views or urls.py

THE SUSPECTS

This code snippet relates to "startproject takehome"

urls.py

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

urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^markdown/', include("django_markdown.urls")),
    url(r'^', include('blog.urls')),
)

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'blog',
    'django_markdown',
)

These three code snippets relate to the app called "Blog"

Urls.py

from django.conf.urls import patterns, url
from . import views

urlpatterns = patterns(
    '',
    url(r'^$', views.BlogIndex.as_view(), name="list"),
    url(r'^(?P<slug>\S+)$', views.BlogDetail.as_view(), name="detailed"),
)

Models.py

from django.db import models
from django.core.urlresolvers import reverse

# Create your models here.
class FullArticleQuerySet(models.QuerySet):
    def published(self):
        return self.filter(publish=True)

class FullArticle(models.Model):
    title = models.CharField(max_length=150)
    author = models.CharField(max_length=150)
    slug = models.SlugField(max_length=200, unique=True)
    pubDate = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    category = models.CharField(max_length=150)
    heroImage = models.CharField(max_length=250, blank=True)
    relatedImage =  models.CharField(max_length=250, blank=True)
    body =  models.TextField()
    publish = models.BooleanField(default=True)
    gameRank = models.CharField(max_length=150, blank=True, null=True)

    objects = FullArticleQuerySet.as_manager()

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("FullArticle_detailed", kwargs={"slug": self.slug})

    # def random(self):
    #   return self.get_queryset().order_by('?').values('title','author','heroImage','body').first()

    class Meta:
        verbose_name = "Blog entry"
        verbose_name_plural = "Blog Entries"
        ordering = ["-pubDate"]

views.py

from django.views import generic
from . import models 

# Create your views here.
class BlogIndex(generic.ListView):
    queryset = models.FullArticle.objects.published()
    template_name = "list.html"
    # paginate_by = 2

class BlogDetail(generic.DetailView):
    model = models.FullArticle
    template_name = "detailed.html"

# random = models.FullArticle.objects.order_by('?').values('title','author','heroImage','body').first()

解决方案

Update: ok the migration problem has been moved out of the way.

Update 2: ok so it isn´t lacking the admin url pattern

What is the case with your importing the blog urls in your main urls.py? You match everything that falls through the patterns r'^admin/' and r'^markdown/' as a blog entry. Now your request is "/admin", and because of the lacking of a "/" (slash) at the end, in stead of being matched against the first pattern, it is matched against the last one: r'^(?P\S+)$'. So now it looks for blog entry with a slug called "admin", and fails to find one, and hence returns 404 with a very clear discription. (next time don´t hesitate to include that in the question :)

I expect also that requesting "/admin/" will result in an admin page, because it would get matched against r'^admin/', because of the trailing /

better practice is to avoid conflicts between main urls and app specific urls by sub-url'ing your blogposts somewhat like this:

url(r'^blog/', include('blog.urls', namespace="blog")),

https://docs.djangoproject.com/en/dev/intro/tutorial03/#namespacing-url-names


before update: Maybe you tried to make the order field unique after having non-unique values in it. Have you tried removing the whole database and rebuilding it? That would be my first suggestion.

It seems like there are some quirks in sqlite, I never use it basically. I would suggest also to try using something more mature like postgresql or mysql.

这篇关于无法登录到Django admin 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆