ace.js and markdown.js errors with django.contrib.staticfiles.storage.ManifestStaticFilesStorage #197
Closed
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)
- 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
- 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)
- 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,
})
- create the testapp/templates/template.html file:
{{ form.media }}
<form action="{% url 'test_edit' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
</form>
- 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'),
]
- 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,
}),
]
- 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',
]
- run:
./manage.py createsuperuser
./manage.py makemigrations
./manage.py migrate
./manage.py collectstatic
./manage.py runserver
- navigate to http://localhost:8000/test/ and view these errors:
- Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes or with webpack use ace/webpack-resolver
- GET http://localhost:8000/test/snippets/markdown.js net::ERR_ABORTED 404 (Not Found)
- Refused to execute script from 'http://localhost:8000/test/snippets/markdown.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
- 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>
- If you comment this line from settings/settings.py, everying loads as expected:
# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
Metadata
Assignees
Labels
No labels