我试图在我的Django网站上添加一个功能,该网站实现了由管理员写下一些降价的文章。
我安装了django-markdown,并遵循了本教程: http://pythonhosted.org/django-markdown/
我makemigrations / migrate和runserver,我成功访问了我的网站,但是当我尝试访问管理界面时,我遇到了一个问题:
No installed app with label 'flatpages'.
以下是我的要求的内容.txt:
Django==1.7.5
django-markdown==0.8.4
Markdown==2.6
wheel==0.24.0
我认为它是django_markdown模块的flatpages。 我尝试了一些东西,比如添加平板电脑'到INSTALLED_APPS。但这并没有解决问题(而且已经在其中已经有了#django_markdown')。 我对django没有足够的经验来理解我的项目中发生了什么,我需要一些帮助来理解这个问题。 有人可以帮帮我吗?
错误:
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.7.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_markdown',
'main')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
227. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
206. return view(request, *args, **kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in index
401. 'name': apps.get_app_config(app_label).verbose_name,
File "/home/vmonteco/Envs/django/local/lib/python2.7/site-packages/django/apps/registry.py" in get_app_config
150. raise LookupError("No installed app with label '%s'." % app_label)
Exception Type: LookupError at /admin/
Exception Value: No installed app with label 'flatpages'.
催眠/ settings.py:
"""
Django settings for hypnose project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Template dirs.
TEMPLATE_DIRS = [
os.path.join(BASE_DIR, 'templates'),
]
# Static dirs.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
#Email settings
#markdown flatpages
# import django_markdown
MARKDOWN_EDITOR_SKIN = 'simple'
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_markdown',
# 'django.contrib.flatpages',
#'django_markdown.flatpages',
'main',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'hypnose.urls'
WSGI_APPLICATION = 'hypnose.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
hypnose / urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django_markdown import flatpages
admin.autodiscover()
flatpages.register()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url('^markdown/', include('django_markdown.urls')),
url(r'^', include('main.urls')),
)
main / admin.py:
from django.contrib import admin
from main.models import Article
from django_markdown.admin import MarkdownModelAdmin
admin.site.register(Article, MarkdownModelAdmin)
主要/ models.py
from django.db import models
from django_markdown.models import MarkdownField
from django_markdown.widgets import MarkdownWidget
from django import forms
from django.forms.widgets import *
class Article(models.Model):
title = models.CharField(max_length = 100)
# I just changed content from forms.CharField to MarkdownField
# because this field wasn't appearing in
# my admin pannel.
# content = forms.CharField(required = False, widget=MarkdownWidget())
content = MarkdownField(null = True)
date = models.DateTimeField(auto_now_add = True, auto_now = False, verbose_name = "Date de parution")
slug = models.SlugField(max_length = 50)
def __unicode__(self):
return (u"%s" % (self.title,))
def __str__(self):
return ("%s" % (self.title,))
它可能是什么,我该怎么办? 谢谢您的帮助。 :)
编辑:
问题解决了,但是为了解释模板中的降价,我还必须安装django-markdown-deux:
https://github.com/trentm/django-markdown-deux
答案 0 :(得分:6)
flatpages应用是part of Django。您需要正确安装它。从官方安装文档:
要安装flatpages应用,请按以下步骤操作:
- 通过将
醇>'django.contrib.sites'
添加到INSTALLED_APPS
设置来安装网站框架(如果它尚未存在)。另外,请确保您已将
SITE_ID
正确设置为设置文件所代表的网站的ID
。这通常是1
(即SITE_ID = 1
,但如果您使用网站框架来管理多个网站,则可能是其他网站的ID。
- 醇>
将
'django.contrib.flatpages'
添加到您的INSTALLED_APPS
设置中。然后:(a)在您的URLconf中添加一个条目。例如:
urlpatterns = patterns('',
(r'^pages/', include('django.contrib.flatpages.urls')),
)
或(b)将
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
添加到MIDDLEWARE_CLASSES
设置。
- 运行命令
醇>manage.py migrate
。