Django Markdown Editor Not Displaying

I am building my first Django application (I am also starting in Python, so the problem could be anywhere.)

I follow this guide 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 in diagnosing the problem would be greatly appreciated. Thanks!

My files:

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"] 

projects /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/' 
+2
source share
6 answers

In the comments to the video you can get an answer. Modify the following 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) 

In the shell run:

 python manage.py collectstatic 
+6
source

I have the same problem. However, when I add the iago1460 code without the urls.py part, after starting:

 python manage.py collectstatic, 

django_markdown may work, I am using python 2.7 and django version 1.8

urls.py code is here

 from django.conf.urls import include, url from django.contrib import admin #import settings #if settings.DEBUG: #from django.conf.urls.static import static #urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT) urlpatterns = [ # Examples: # url(r'^$', 'cblog.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^markdown/', include("django_markdown.urls")), url(r'^',include('blog.urls')), 

]

here are my project files, my project name is cblog, the application is a blog:

djtest / cblog / cblog:

 __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc 

djtest / cblog:

  blog cblog db.sqlite3 manage.py static 
+1
source

Yes, I also found this problem when I tried to try qblog. I use Python 3.4 and Django 1.8.1, but during the installation phase of the markdown package, I decided to change the package in Django CKEditor.

Visit https://pypi.python.org/pypi/django-ckeditor to install.

After CKEditor is installed correctly, if you find a problem in import forms.util flattat when you use the server. Change your widgets.py in the ckeditor folder (on Windows, the directory is under C: \ Python34 \ Lib \ site-packages \ ckeditor), then change the line:

from django.forms.util import flatatt

to

from django.forms.utils import flatatt

Follow how to use CKEditor, then implement it on your qblog. The result will be like this:

enter image description here

+1
source

Try this simple method:

in admin.py :

 from django_markdown.admin import MarkdownModelAdmin from django_markdown.widgets import AdminMarkdownWidget from django.db.models import TextField class EntryAdmin(MarkdownModelAdmin): ... #your_code formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}} admin.site.register(models.Entry, EntryAdmin) 
+1
source

This happens when you use python 2x Now it happens that style sheets and javascript are not loading

So what you can do:

 from django_markdown.widgets import AdminMarkdownWidget from django.db.models import TextField class EntryAdmin(MarkdownModelAdmin): list_display = ("title", "created") prepopulated_fields = {"slug": ("title",)} # Next line is a workaround for Python 2.x formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}} 

and it will work !!!!!!!!!!!!!

0
source

Python 2.x You need to add that:

formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}}

0
source

All Articles