python - Django Markdown 编辑器不显示

标签 python django django-admin django-apps

我正在创建我的第一个 Django 应用程序(我也是 Python 的新手,所以问题可能出在任何地方。)

我正在逐步按照本教程进行操作,以在 5:53 ( here ) 获取 HTML 编辑器,但是我仍然在 http://127.0.0.1:8000/admin/blog/entry/add/ 获取默认的 TextField

如果您能提供有关诊断问题的任何帮助,我们将不胜感激。 谢谢!

我的文件:

项目/qblog/blog/admin.py :

from django.contrib import admin
from . import models
from django_markdown.admin import MarkdownModelAdmin

class EntryAdmin(MarkdownModelAdmin):
    list_display = ("title" , "created")
    prepopulated_fields = {"slug" : ("title", )}

admin.site.register(models.Entry, EntryAdmin)

项目/qblog/qblog/urls.py :

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


urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^markdown/', include("django_markdown.urls")),
)

项目/qblog/blog/models.py :

from django.db import models

# Create your models here.

class EntryQuerySet(models.QuerySet):
    def published(self):
        return self.filter(publish=True)

class Entry(models.Model):
    title=models.CharField(max_length=200)
    body = models.TextField()
    slug = models.SlugField(max_length=200,unique = True)
    publish = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add = True)
    modified = models.DateTimeField(auto_now = True)

    objects = EntryQuerySet.as_manager()

    def __str__(self):
        return self.title
    class Meta:
        verbose_name = "Blog Entry"
        verbose_name_plural = "Blog Entries"
        ordering = ["-created"]

项目/qblog/qblog/settings.py :

"""
Django settings for qblog project.

Generated by 'django-admin startproject' using Django 1.9.dev20150210173028.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secretkey'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'blog',
    'django_markdown',
]

MIDDLEWARE_CLASSES = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
]

ROOT_URLCONF = 'qblog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'qblog.wsgi.application'


# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/dev/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/dev/howto/static-files/

STATIC_URL = '/static/'

最佳答案

在视频的评论中你可以得到答案。修改下一个文件:

模型.py

from django_markdown.models import MarkdownField
...
body = MarkdownField()

settings.py

...
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

# Markdown
MARKDOWN_EDITOR_SKIN = 'simple'

urls.py

...
from yourapp import settings
if settings.DEBUG:
    from django.conf.urls.static import static
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

在 shell 中运行:

python manage.py collectstatic

关于python - Django Markdown 编辑器不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440383/

相关文章:

javascript - 使用Python解析decodeURIComponent JSON字符串

python fuzzywuzzy 的 process.extract() : how does it work?

python - Django 的@login_required 装饰器在人们未注册时将他们重定向到/accounts/login。如何更改此网址?

python - 将 django 项目编译为桌面应用程序

python - 是否可以在 Django admin 中禁用字段?

python pandas 溢出错误数据帧

python - VPython 7 - 没有找到模块可视化

python - 使用内联表单集和模型表单在管理员中进行表单验证

django-staticfiles 破坏了管理界面

django - 如何重置 Django 管理员密码?