2012-04-07 5 views
0

Wenn ich settings.DEBUG = False gesetzt habe, verliere ich den Zugriff auf meine Apps im Dashboard außer Auth und Websites. Es funktioniert gut mit settings.DEBUG = True.Zugriff auf meine App im Dashboard in Django verlieren

# Django settings for blog project. 
import sys 
PROJECT_PATH=r'/home/www/blog' 
if not PROJECT_PATH in sys.path: 
    sys.path.insert(0,PROJECT_PATH) 


DEBUG =False 

TEMPLATE_DEBUG =False 

ADMINS = (
    # ('Your Name', '[email protected]'), 
) 

MANAGERS = ADMINS 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': '/home/www/blog/database.db',      # Or path to database file if using sqlite3. 
     'USER': '',      # Not used with sqlite3. 
     'PASSWORD': '',     # Not used with sqlite3. 
     'HOST': '',      # Set to empty string for localhost. Not used with sqlite3. 
     'PORT': '',      # Set to empty string for default. Not used with sqlite3. 
    } 
} 

# Local time zone for this installation. Choices can be found here: 
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 
# although not all choices may be available on all operating systems. 
# On Unix systems, a value of None will cause Django to use the same 
# timezone as the operating system. 
# If running in a Windows environment this must be set to the same as your 
# system time zone. 
TIME_ZONE = 'Asia/Shanghai' 

# Language code for this installation. All choices can be found here: 
# http://www.i18nguy.com/unicode/language-identifiers.html 
LANGUAGE_CODE = 'zh-cn' 

SITE_ID = 1 

# If you set this to False, Django will make some optimizations so as not 
# to load the internationalization machinery. 
USE_I18N = True 

# If you set this to False, Django will not format dates, numbers and 
# calendars according to the current locale. 
USE_L10N = True 

# If you set this to False, Django will not use timezone-aware datetimes. 
USE_TZ = True 

# Absolute filesystem path to the directory that will hold user-uploaded files. 
# Example: "/home/media/media.lawrence.com/media/" 
MEDIA_ROOT = '/home/www/blog/media/' 

# URL that handles the media served from MEDIA_ROOT. Make sure to use a 
# trailing slash. 
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" 
MEDIA_URL = '/media/' 

# Absolute path to the directory static files should be collected to. 
# Don't put anything in this directory yourself; store your static files 
# in apps' "static/" subdirectories and in STATICFILES_DIRS. 
# Example: "/home/media/media.lawrence.com/static/" 
STATIC_ROOT = '/home/www/blog/staticDir/' 

# URL prefix for static files. 
# Example: "http://media.lawrence.com/static/" 
STATIC_URL = '/static/' 

# Additional locations of static files 
STATICFILES_DIRS = (
    '/home/www/blog/static/', 
    # Put strings here, like "/home/html/static" or "C:/www/django/static". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
) 

# List of finder classes that know how to find static files in 
# various locations. 
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
# 'django.contrib.staticfiles.finders.DefaultStorageFinder', 
) 


# List of callables that know how to import templates from various sources. 
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader', 
    'django.template.loaders.app_directories.Loader', 
#  'django.template.loaders.eggs.Loader', 
) 

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    # Uncomment the next line for simple clickjacking protection: 
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'blog.urls' 

# Python dotted path to the WSGI application used by Django's runserver. 
WSGI_APPLICATION = 'blog.wsgi.application' 

TEMPLATE_DIRS = (
    '/home/www/blog/templates', 
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
) 


INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
    'article', 
    'guestbook', 
    'multimedia', 
    'archive', 
    'about', 
) 

# A sample logging configuration. The only tangible logging 
# performed by this configuration is to send an email to 
# the site admins on every HTTP 500 error when DEBUG=False. 
# See http://docs.djangoproject.com/en/dev/topics/logging for 
# more details on how to customize your logging configuration. 
LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': False, 
    'filters': { 
     'require_debug_false': { 
      '()': 'django.utils.log.RequireDebugFalse' 
     } 
    }, 
    'handlers': { 
     'mail_admins': { 
      'level': 'ERROR', 
      'filters': ['require_debug_false'], 
      'class': 'django.utils.log.AdminEmailHandler' 
     } 
    }, 
    'loggers': { 
     'django.request': { 
      'handlers': ['mail_admins'], 
      'level': 'ERROR', 
      'propagate': True, 
     }, 
    } 
} 

hier ist eine App namens Artikel:

# coding:utf-8 
from markdown import markdown 
import datetime 

from django.db import models 

from django.contrib import admin 

VIEWABLE_STATUS = [2,] 

class ViewableManager(models.Manager): 
    """ 
     改写 Model.objects 的 get_query_set 方法 
     objects 不能接触状态为不可见的 Article 类的实体 
    """ 
    def get_query_set(self): 
     default_queryset = super(ViewableManager, self).get_query_set() 
     return default_queryset.filter(status__in=VIEWABLE_STATUS) 

class Article(models.Model): 
    """ 
     文章类 
    """ 
    STATUS_CHOICES=((1,'Editing'), 
        (2,'Posted'),) 
    articleID=models.AutoField(primary_key=True) 
    title=models.CharField(max_length=50,unique=True) 
    slug = models.SlugField(max_length=50,unique=True) 
    postDate=models.DateField() 
    lastUpdate=models.DateTimeField(auto_now=True,auto_now_add=True) 
    keywords=models.CharField(max_length=140,blank=True) 
    markdown_content=models.TextField() 
    html_content=models.TextField(editable=False) 
    status=models.IntegerField(choices=STATUS_CHOICES,default=1) 
    class Meta: 
     ordering=['-postDate','-lastUpdate'] 

    def get_url(self): 
     return r'/article/'+str(self.slug) 
    def __unicode__(self): 
     return self.title 
    def saveCategories(self): 
     self.articleCategories.clear() 
     categoryList=self.keywords.split() 
     for category in categoryList: 
      c=Category.objects.filter(label=category) 
      if c: 
       self.articleCategories.add(c[0]) 
      else: 
       self.articleCategories.create(label=category)     

    def save(self): 
     self.html_content=markdown(self.markdown_content) 
     self.lastUpdate=datetime.datetime.now() 
     super(Article,self).save() 
     self.saveCategories() 
     print self.html_content 
     print self.lastUpdate 
     super(Article,self).save() 

    admin_objects=models.Manager() 
    objects=ViewableManager() 

class ArticleAdmin(admin.ModelAdmin): 
    list_display = ('title', 'status', 'postDate', 'lastUpdate') 
    search_fields = ('title', 'keywords','content') 
    list_filter = ('status', 'postDate', 'lastUpdate') 

admin.site.register(Article, ArticleAdmin) 

class Category(models.Model): 
    label=models.CharField(max_length=30,unique=True) 
    masterArticle=models.ManyToManyField(Article,related_name='articleCategories',blank=True) 
    class Meta: 
     verbose_name_plural = "categories" 
    def __unicode__(self): 
     return self.label 
class CategoryAdmin(admin.ModelAdmin): 
    pass 

admin.site.register(Category, CategoryAdmin) 

Und andere namens App Gästebuch

# coding:utf-8 
from django.db import models 
from django.contrib import admin 
from md5 import md5 
from article.models import Article 

class guestMessage(models.Model): 
    guestName=models.CharField(max_length=50) 
    guestEmail=models.EmailField(max_length=75) 
    gravatarHash=models.CharField(max_length=33,blank=True) 
    content=models.TextField() 
    postDate=models.DateTimeField(auto_now_add=True) 
    article=models.ForeignKey(Article,blank=True,null=True, 
           related_name='guestMessage') 
    def save(self): 
     super(guestMessage,self).save() 
     self.gravatarHash=(md5(self.guestEmail)).hexdigest() 
     super(guestMessage,self).save()  


class guestMessageAdmin(admin.ModelAdmin): 
    list_display = ('guestName', 'article', 'postDate') 
    search_fields = ('guestName', 'article','content') 
    list_filter = ('article', 'postDate') 

admin.site.register(guestMessage, guestMessageAdmin) 

hier ist die urls.py

from django.conf.urls.defaults import patterns, include, url 
from django.conf import settings 
from django.conf.urls.static import static 
# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    url(r'^admin/', include(admin.site.urls)), 
) 
urlpatterns += patterns('article.views', 
    url(r'^$', 'index'), 
    url(r'^article/([\S]+)$', 'articleDetail'), 
    url(r'^category/([\S]+)$','articleBYcategory'), 
    url(r'^search/$','atricleSearch'), 
) 

urlpatterns += patterns('guestbook.views', 
    url(r'^guestbook/$','guestbook'), 
) 

urlpatterns += patterns('archive.views', 
    url(r'^archive/$','archive'), 
) 

urlpatterns += patterns('about.views', 
    url(r'^about/$','about'), 
) 

www.mysite. com/admin: Es gibt keinen Link zum Hinzufügen oder Ändern. Ich habe keine Erlaubnis? Bildlink: http://img3.douban.com/view/photo/photo/public/p1499852307.jpg

+0

Zeigen Sie uns Ihren Dashboard-Code und Einstellungen – ilvar

+0

@ilvar Danke, dass Sie mich daran erinnern. – supei

+0

Sorry, ich habe Django-Admin-Tools-Dashboard gemeint. Außerdem sehe ich keine django-admin-tools auf deinem screenshot, sondern nur Djangos admin. – ilvar

Antwort

0

Ich habe keine anderen Ideen als verschieben Registrierung Verwaltungsseiten aus models. Offizielle Dokumente sagen über sie in separaten Modul admin.

Verwandte Themen