模型没有在Django Admin中显示

时间:2015-02-02 00:20:55

标签: python django

我已经看过很多关于此的帖子,并尝试了大部分答案所说的并且没有运气。

我有一个名为照片的应用程序,其中的models.py看起来像这样

from django.db import models

class Photo(models.Model):
    name = models.CharField(max_length=200)
    location = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    def __unicode__(self):
            return self.name

已安装该应用:

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

Admin.py是这样的:

from photos.models import Photo
from django.contrib import admin

class PhotoAdmin(admin.ModelAdmin):
    pass

admin.site.register(Photo, PhotoAdmin)

urls.py

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

admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'garthreckers.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
)

我在settings.py和wsgi.py上运行了一下。我有runserver,syncdb,migrate。

如果有帮助,这里是我的目录结构的细分:

garthreckers
|-garthreckers
  |-__init__.py
  |-__init__.pyc
  |-settings.py
  |-settings.pyc
  |-urls.py
  |-wsgi.py
  |-wsgi.pyc
|-photos
  |-migrations
  |-__init__.py
  |-__init__.pyc
  |-admin.py
  |-admin.pyc
  |-models.py
  |-models.pyc
  |-tests.py
  |-views.py
|-manage.py

编辑:vhost conf文件

WSGIPythonPath /home/ubuntu/xxxxxxx.com/garthreckers

<VirtualHost *:80>

ServerName www.xxxxxxx.com
ServerAlias xxxxxxx.com

WSGIScriptAlias / /home/ubuntu/xxxxxxx.com/garthreckers/garthreckers/wsgi.py

<Directory /home/ubuntu/xxxxxxx.com/garthreckers/garthreckers>
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files> 
</Directory> 
<Directory /home/ubuntu/xxxxxxx.com/garthreckers/static>
    Require all granted
</Directory> 
<Directory /home/ubuntu/xxxxxxx.com/garthreckers/media>
    Require all granted
</Directory>
</VirtualHost>

2 个答案:

答案 0 :(得分:0)

你的代码很好。我设置了一个新的virtualenv,一个新的Django安装,逐字复制你的代码,管理员就像预期的那样。我无法猜出什么是特别错误,但是,嘿!好消息你的代码很好。开始新鲜很快,所以也许值得一试。删除所有.pyc文件,并且不用担心Apache。一旦您知道项目设置正常,那么您可以担心Apache托管的下一步。以下是我运行的命令:

django-admin startproject garthreckers
django-admin startapp photos
# copied your code into appropriate files
./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
./manage.py runserver

小贴士:从Django 1.7开始,你不需要admin.autodiscover()documentation)。

答案 1 :(得分:0)

检查登录管理面板的用户是否有权管理此类型号。