Django Admin: not seeing any app (permission probl

2019-01-24 13:41发布

问题:

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'),

回答1:

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.



回答2:

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).



回答3:

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.



回答4:

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?


回答5:

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



回答6:

I had the same problem, my settings file was like follow:

    PROJECT_APPS = (
        'app1',
        'app2',
    )

INSTALLED_APPS = (

    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.flatpages',

    # django-allauth settings
    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    # auth providers
    'allauth.socialaccount.providers.facebook',

    'storages',
    'compressor',
    'south',

    'gunicorn',
    'kombu.transport.django',
    'djcelery',

    'django_nose',
    'raven.contrib.django.raven_compat',

    'djrill',
    'django_newsfeed'

) + PROJECT_APPS

I forgot to add , after django_newsfeed