Django 管理页面未显示

发布于 2024-10-03 00:50:55 字数 1977 浏览 1 评论 0原文

我一直在关注民意调查教程,直到我应该有一个管理后端的登录页面。 http://docs.djangoproject.com/en/dev/intro/tutorial02/< /a>

相反,我得到如下欢迎页面:

What I get attempts to access the admin page

我已启用管理员应用程序在 INSTALLED_APPS 中,同步了数据库并调整了 urls.py 所以我不确定问题是什么。

使用 mod_wsgi 运行 apache2。

网址.py: from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
 from django.contrib import admin
 admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^testproject/', include('testproject.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     (r'^admin/', include(admin.site.urls)),
)

Settings.py:

...
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable the admin:
     'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
     'django.contrib.admindocs',
     'polls'
)
...

表:

数据库已更改

mysql> SHOW TABLES;
+----------------------------+
| Tables_in_django_test      |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_message               |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_session             |
| django_site                |
| polls_choice               |
| polls_poll                 |
+----------------------------+

I've been following the polls tutorial up until the point where I should have a login page for the admin backend. http://docs.djangoproject.com/en/dev/intro/tutorial02/

Instead I get the welcome page like this:

What I get trying to access the admin page

I have enabled the admin app in INSTALLED_APPS, synced the db and tweaked urls.py so I'm not sure what the problem is.

Running apache2 with mod_wsgi.

urls.py:
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
 from django.contrib import admin
 admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^testproject/', include('testproject.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     (r'^admin/', include(admin.site.urls)),
)

Settings.py:

...
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable the admin:
     'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
     'django.contrib.admindocs',
     'polls'
)
...

Tables:

Database changed

mysql> SHOW TABLES;
+----------------------------+
| Tables_in_django_test      |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_message               |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_session             |
| django_site                |
| polls_choice               |
| polls_poll                 |
+----------------------------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆梦 2024-10-10 00:50:55

这两行真的如您的帖子中所示缩进一个空格吗?

 from django.contrib import admin
 admin.autodiscover()

如果你这样做,你会得到一个缩进错误。将它们与左边距齐平。


后来:哦,我在上面的评论中看到您发现了这个缩进错误。将我的答案标记为社区维基。

Are these two lines really indented one space, as appears in your post?

 from django.contrib import admin
 admin.autodiscover()

You'll get an IndentationError if you do that. Put them flush against the left margin.


Later: Oh I see in a comment above that you found this indentation error. Marking my answer as community wiki.

二货你真萌 2024-10-10 00:50:55

如果您通过 Apache 和 mod_wsgi 执行此操作,那么您就没有遵循本教程。本教程告诉您使用开发服务器,这是有充分理由的:使用 Apache,每当您更改代码时都需要重新启动它。开发服务器会检测到更改并为您重新启动。

If you're doing this via Apache and mod_wsgi, then you're not following the tutorial. The tutorial tells you to use the development server, for a good reason: with Apache, you need to restart it whenever you make a code change. The dev server detects changes and restarts itself for you.

泪眸﹌ 2024-10-10 00:50:55

我有一个相同的错误。即使我请求了 domain.com/admin,我也只得到了欢迎页面。不确定我们的错误是否是由于相同的来源造成的,因为我正在使用 mod_fcgid 在 hostgator 上运行我的 django 站点。

不管怎样,通过为 python 添加更具体的自定义路径解决了我的问题,一直到包含我的 wsgi.py 文件的目录。

我的index.fcgi 文件是:

...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")

# Switch to the directory of your project.
...

现在是:

...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")
sys.path.insert(0, "/home/*username*/django/mysite")
sys.path.insert(0, "/home/*username*/django/mysite/mysite")

# Switch to the directory of your project.
...

我认为这是由于欢迎页面代码位于比管理代码更靠近路径列表开头的路径。

I had an identical error. I only got the welcome page even though I requested domain.com/admin. Not sure if our errors are due to identical sources though because I'm running my django site on hostgator with mod_fcgid.

Anyway, solved my problem by adding more specific custom paths for python, all the way down to the dir containing my wsgi.py file.

My index.fcgi file was:

...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")

# Switch to the directory of your project.
...

Now it is:

...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")
sys.path.insert(0, "/home/*username*/django/mysite")
sys.path.insert(0, "/home/*username*/django/mysite/mysite")

# Switch to the directory of your project.
...

I assume this is due to the welcome page code being located along a path located nearer the beginning in the list of paths than the admin code is.

献世佛 2024-10-10 00:50:55

正如 @Daniel 所提到的,Apache 中的 mod_wsgi 默认情况下不会接收代码更改。但是,可以对其进行配置来执行此操作。请参阅:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode #Monitoring_For_Code_Changes

As mentioned by @Daniel, mod_wsgi in Apache doesn't pick up code changes by default. However, it can be configured to do so. See:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文