Skip to content

ace.js and markdown.js errors with django.contrib.staticfiles.storage.ManifestStaticFilesStorage #197

Closed
@sodrew

Description

This was mentioned in #55, but without real instructions to reproduce.

Details

OS (Operating System) version: Windows 11
Browser and browser version: MS Edge 108.0.1462.76 (Official build) (64-bit)
Django version: 3.2.16 (my webhost won't upgrade to 4.x)
Martor version & theme: 1.6.16

Steps to reproduce (some of this is really nitty gritty, but wanted to be clear how barebones this was)

  1. Start with a fresh install of django 3.2.16
virtualenv martortest -p python3
. martortest/bin/activate
pip install Django==3.2.16 martor==1.6.16
cd martortest
django-admin startproject settings
cd settings
./manage.py startapp testapp
mkdir -p testapp/templates
  1. replace the testapp/models.py file:
from django.db import models
from martor.models import MartorField

class MyModel(models.Model):
    brief = MartorField(null=True, blank=True)

  1. replace the testapp/views.py file:
from django.shortcuts import render
from django.forms import ModelForm, Textarea, DateInput

from .models import *

class MyModelForm(ModelForm):

    class Meta:
        model = MyModel
        fields = '__all__'

def test_edit(request):
    form = MyModelForm(request.POST or None,
                       instance=None)

    return render(request, 'template.html', {
        'form': form,
    })

  1. create the testapp/templates/template.html file:
{{ form.media }}

<form action="{% url 'test_edit' %}" method="post">
    {% csrf_token %}
    {{ form.as_p }}
</form>

  1. create the testapp/urls.py file:
from django.contrib import admin
from django.urls import path, include, re_path

from .views import *

urlpatterns = [
    path('', test_edit, name='test_edit'),
]

  1. update the settings/urls.py file
from django.contrib import admin
from django.urls import path, include, re_path
from django.conf import settings
from django.views.static import serve

urlpatterns = [
    path('admin/', admin.site.urls),
    path('martor/', include('martor.urls')),
    path('test/', include('testapp.urls')),
    # line below needed so that static files will be served without an external web server when DEBUG is set to false
    re_path(r'^static/(?P<path>.*)$', serve, {
        'document_root': settings.STATIC_ROOT,
        'show_indexes': True,
    }),
]

  1. Set these variables settings/settings.py:
DEBUG=False
ALLOWED_HOSTS = ['localhost']
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
STATIC_ROOT = 'static'
INSTALLED_APPS += [
    'martor',
    'testapp',
]

  1. run:
./manage.py createsuperuser
./manage.py makemigrations
./manage.py migrate
./manage.py collectstatic
./manage.py runserver
  1. navigate to http://localhost:8000/test/ and view these errors:
  1. View the dom. Instead of seeing:

<script src="http://localhost:8000/static/plugins/js/snippets/markdown.js"></script></head><body>

you see:

<script src="snippets/markdown.js"></script></head><body>

  1. If you comment this line from settings/settings.py, everying loads as expected:
# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions