2012-04-07 22 views
0

當我設置settings.DEBUG = False時,除了auth和網站之外,我無法訪問儀表板中的應用程序。它使用settings.DEBUG = True可以正常工作。在Django的儀表板上失去對我的應用程序的訪問

# 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, 
     }, 
    } 
} 

這裏是一個應用程序命名的文章:名爲留言

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

這裏

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

與其他應用程序是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:沒有添加或更改鏈接。我沒有權限? 圖片鏈接:http://img3.douban.com/view/photo/photo/public/p1499852307.jpg

+0

向我們顯示您的儀表板代碼和設置 – ilvar 2012-04-08 03:56:19

+0

@ilvar感謝提醒我這一點。 – supei 2012-04-09 04:48:49

+0

對不起,我的意思是django-admin-tools dashboard。另外,我的屏幕截圖上沒有看到django-admin-tools,只是簡單的Django的管理員。 – ilvar 2012-04-09 05:11:33

回答

0

我沒有其他的想法移動登記管理網站登出models。官方文檔說他們居住在單獨的admin模塊。