Django Markdown Editor不显示 [英] Django Markdown Editor does not show up

查看:206
本文介绍了Django Markdown Editor不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating my very first Django application (I'm also a novice at Python, so the problem could be anywhere.)

我正在关注教程一步一步,在5:53(这里)获取HTML编辑器,但是我仍然获取默认的TextField在 http://127.0.0.1:8000/admin/blog/entry / add /

I'm following this tutorial step by step, to get the HTML editor at 5:53 (here), however I still get the default TextField at http://127.0.0.1:8000/admin/blog/entry/add/

任何有关诊断问题的帮助都不胜感激。
谢谢!

Any help on diagnosing the problem would be appreciated. Thanks!

projects / 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)

projects / 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")),
)

projects / 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/'


推荐答案

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

In the video's comments you can get the answer. Modify the next files:

models.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

这篇关于Django Markdown Editor不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆