views:

614

answers:

4

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  A: 

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?
celopes
Thanks for your answer.All the apps are in the settings, none is showing. I also checked the database and the user has is_superuser on.
Facundo
Is this happening when you run manage.py runserver?
celopes
Ok, celopes, you are close. When I run the development server the Admin shows everything.I just don't get it. I was doing heavy editing on this site, if the settings.py file wasn't correct I shouldn't be able to work on it.However when I see it from Apache it doesn't work but it appears to work from the development server.
Facundo
* /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
Facundo
Does /var/django/gpx/contable/ have its own \_\_init\_\_.py? It should if you created it with manage.py startapp contable - but just checking
celopes
I have completely run out of ideas... Your urls.py doesn't show the admin.autodiscover(), but you already said it is there. I don't know what else to think... If something comes to me I'll edit the answer.
celopes
A: 

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.

aldux
+2  A: 

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

John Debs
+1 - if the autodiscover wasn't done, app_list will be blank for index.html in admin and you'll see that message.
celopes
Thanks, this was ok, I had those lines in urls.py.
Facundo
A: 

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