Django 管理员:没有看到任何应用程序(权限问题?)

发布于 2024-08-15 13:39:49 字数 1387 浏览 6 评论 0原文

我有一个 Django 网站,运行一些自定义应用程序。我没有使用 Django ORM,只是使用视图和模板,但现在我需要存储一些信息,因此我在一个应用程序中创建了一些模型并启用了管理。

问题是当我登录管理员时,它只是说“您无权编辑任何内容”,甚至页面中都没有显示身份验证应用程序。我使用使用syncdb 创建的同一用户作为超级用户。

在同一台服务器中,我有另一个正在使用管理员的站点。

在 Gentoo Linux 2.6.23 中使用 Django 1.1.0 和 Apache/2.2.10 mod_python/3.3.1 Python/2.5.2,以及 psql (PostgreSQL) 8.1.11

有什么想法可以找到解决方案吗?

多谢。

更新:它可以在开发服务器上运行。我敢打赌这与某些文件系统权限有关,但我就是找不到它。

UPDATE2:虚拟主机配置文件:

<Location />
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE gpx.settings
  PythonDebug On
  PythonPath "['/var/django'] + sys.path"
</Location>

UPDATE 3:更多信息

  • /var/django/gpx/init.py 存在并且为空
  • 我从 /var/django/gpx 目录运行 python manage.py
  • 该站点是 GPX ,其中一个应用程序是 contable 并位于 /var/django/gpx/contable
  • 用户 apache 是 webdev 组,所有这些目录和文件都属于该组并具有 rw 权限

更新 4:确认设置文件与apache 和 runserver (重命名后都损坏了)

更新 5:/var/django/gpx/contable/init.py 存在

这是 urls.py 的相关部分:

urlpatterns = patterns('',
                       (r'^admin/', include(admin.site.urls)),
                      )
urlpatterns += patterns('gpx',
   (r'^$',                         'menues.views.index'),
   (r'^adm/$',                     'menues.views.admIndex'),

I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.

The problem is when I log in the Admin it just says "You don't have permission to edit anything", not even the Auth app shows in the page. I'm using the same user created with syncdb as a superuser.

In the same server I have another site that is using the Admin just fine.

Using Django 1.1.0 with Apache/2.2.10 mod_python/3.3.1 Python/2.5.2, with psql (PostgreSQL) 8.1.11 all in Gentoo Linux 2.6.23

Any ideas where I can find a solution?

Thanks a lot.

UPDATE: It works from the development server. I bet this has something to do with some filesystem permission but I just can't find it.

UPDATE2: vhost configuration file:

<Location />
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE gpx.settings
  PythonDebug On
  PythonPath "['/var/django'] + sys.path"
</Location>

UPDATE 3: more info

  • /var/django/gpx/init.py exists and is empty
  • I run python manage.py from /var/django/gpx directory
  • The site is GPX, one of the apps is contable and lives in /var/django/gpx/contable
  • the user apache is webdev group and all these directories and files belong to that group and have rw permission

UPDATE 4: confirmed that the settings file is the same for apache and runserver (renamed it and both broke)

UPDATE 5: /var/django/gpx/contable/init.py exists

This is the relevan part of urls.py:

urlpatterns = patterns('',
                       (r'^admin/', include(admin.site.urls)),
                      )
urlpatterns += patterns('gpx',
   (r'^
,                         'menues.views.index'),
   (r'^adm/
,                     'menues.views.admIndex'),

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

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

发布评论

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

评论(5

一人独醉 2024-08-22 13:39:49

希望这对某人有帮助,但我们遇到了同样的问题,因为有人向 settings.py 添加了不同的身份验证后端,并且没有保留默认的 ModelBackend。将设置更改为:

AUTHENTICATION_BACKENDS = (
    'auth.authentication.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

为我们修复了它。

Hopefully this helps someone, but we had this same problem because someone added a different authentication backend to settings.py and did not keep the default ModelBackend. Changing the setting to:

AUTHENTICATION_BACKENDS = (
    'auth.authentication.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

fixed it for us.

段念尘 2024-08-22 13:39:49

听起来您还没有向管理员注册任何应用程序(此概述)。

尝试将行 admin.autodiscover() 添加到您的主 urls.py,确保首先执行 from django.contrib import admin

例如:

# Other imports...
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    ('^admin/', include(admin.site.urls)),
    # Other URL patterns...
)

您还可以使用 admin.site.register(YourModel) 单独注册您的模型。

It sounds like you haven't registered any apps with the admin (step 5 in this overview).

Try adding the line admin.autodiscover() to your main urls.py, making sure to do from django.contrib import admin first.

For example:

# Other imports...
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    ('^admin/', include(admin.site.urls)),
    # Other URL patterns...
)

You can also register your models individually with admin.site.register(YourModel).

揪着可爱 2024-08-22 13:39:49

尝试访问您的数据库,并在表 auth_user 中确保您的用户的字段 is_staff、is_active 和 is_superuser 标记为 true (1)。

Try accessing your database and in the table auth_user make sure that the fiels is_staff, is_active and is_superuser are marked as true (1) for your user.

清引 2024-08-22 13:39:49

确保您已将应用程序添加到settings.INSTALLED_APPS。

管理应用程序索引页的 django 模板如下:

{% if app_list %}
    {% for app in app_list %}
    ...
{% else %}
    <p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}

那一定是你的问题。


编辑:要么您没有以您所说的用户身份登录。您能否查看数据库并确保相关用户的 auth_user.is_superuser 值为 1?


编辑:如果您的用户 is_staff 和 is_superuser 在数据库中被标记为 1,并且您确定您以该用户身份登录;您是否有可能只在生产中(即在 apache 下)看到这一点,并且生产中的 settings.py 与开发中不同?


编辑:所以你在开发和生产中有不同的行为。我可以想到两种情况:

a)您有不同的 settings.py 用于生产。您可以编辑显示 httpd.conf 相关部分的问题吗?它应该类似于:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
</Location>

另外,你的 PYTHONPATH 是什么?

SetEnv 行说的是什么?它是否指向您正在开发的相同模块?您确定在您的 PYTHONPATH 中将 mysite.settings 作为您认为拥有的文件吗?

b) 您在生产中遇到 PYTHONPATH 问题,并且无法找到应用程序。但这应该会产生更严重的错误...


问题:

  • /var/django/gpx 有一个 init.py 正确吗?
  • /var/django/gpx/settings.py 与执行manage.py runserver 时使用的文件相同吗?
  • /var/django/ 中您的应用程序的名称是什么?
  • 您运行 Apache 的用户是否有权访问所有这些目录?

Make sure you have added your application to settings.INSTALLED_APPS.

The django template for the admin app index page reads:

{% if app_list %}
    {% for app in app_list %}
    ...
{% else %}
    <p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}

That must be your problem.


EDIT: Either that or you are not logged in as the user you say you are. Can you look in the database and make sure that the auth_user.is_superuser for the user in question has a value of 1?


EDIT: If you user is_staff and is_superuser are marked as 1 in the DB, and you are sure you are logged in as that user; is it possible that you are only seeing this in production (i.e. under apache) and that your settings.py for production is different than in development?


EDIT: So you have different behavior in dev and production. I can think of two scenarios:

a) You have a different settings.py for production. Can you edit your question showing the relevant portion of your httpd.conf? It should be something like:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
</Location>

Also, what is your PYTHONPATH?

What is the SetEnv line saying? Is it pointing to the very same module you have in development? Are you sure in your PYTHONPATH you have mysite.settings as the file you think you have?

b) You have a PYTHONPATH problem in production and the apps can't be found. This should generate a much more severe error though...


Questions:

  • /var/django/gpx has a init.py correct?
  • /var/django/gpx/settings.py is the same file used as when you do manage.py runserver?
  • What is the name of your app at /var/django/?
  • Does the user your are running Apache under has permissions to all these directories?
淡水深流 2024-08-22 13:39:49

我们在旧安装的 django 0.96 上安装 django 1.1 时遇到了同样的问题,

当我们全新安装时解决了这个问题

We encountered the same problem when installing django 1.1 over an old installation of django 0.96

it was solved when we made a fresh install

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