neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
859 stars 153 forks source link

405 (Method Not Allowed) #107

Closed eriktelepovsky closed 6 years ago

eriktelepovsky commented 6 years ago

Hi. I can't get it work :/ I can see an error at mardownx.js:754:

image

Any help is appreciated, thank you.

Terminal:

[23/Feb/2018 20:19:57] "GET /sk/admin/helpdesk/article/1/change/ HTTP/1.1" 200 31578
[23/Feb/2018 20:19:57] "GET /static/markdownx/admin/css/markdownx.css HTTP/1.1" 304 0
[23/Feb/2018 20:19:57] "GET /sk/admin/jsi18n/ HTTP/1.1" 200 7620
[23/Feb/2018 20:19:57] "POST /markdownx/markdownify/ HTTP/1.1" 302 0
[23/Feb/2018 20:19:57] "POST /markdownx/markdownify/ HTTP/1.1" 302 0
[23/Feb/2018 20:19:57] "GET /en/markdownx/markdownify/ HTTP/1.1" 405 0
[23/Feb/2018 20:19:57] "GET /en/markdownx/markdownify/ HTTP/1.1" 405 0

Installed packages:

Django==2.0.2
django-markdownx==2.0.22
Markdown==2.6.11

models.py:

class Revision(models.Model):
    article = models.ForeignKey(Article, verbose_name=_('article'), on_delete=models.CASCADE)
    content = MarkdownxField(_('content'))

admin.py:

class RevisionInline(admin.StackedInline):
    model = Revision
    extra = 1
    formfield_overrides = {
        MarkdownxField: {'widget': AdminMarkdownxWidget}
    }

@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    inlines = [RevisionInline]
eriktelepovsky commented 6 years ago

I also confirm same error also occurs on frontend in custom form:

class ArticleCreateForm(forms.ModelForm):
    content = MarkdownxFormField()

    class Meta:
        model = Article
        fields = ['content']
eriktelepovsky commented 6 years ago

Issue solved.

Misconfiguration in the urls.py. It seems i18n_patterns are not compatible with the package:

Incorrect:

if 'markdownx' in settings.INSTALLED_APPS:
    urlpatterns += i18n_patterns(
        url(r'^markdownx/', include('markdownx.urls'))
    )

Correct:

if 'markdownx' in settings.INSTALLED_APPS:
    urlpatterns += [
        url(r'^markdownx/', include('markdownx.urls'))
    ]
xenatisch commented 6 years ago

But isn't that what's highlighted in the documentations?

See translations for additional info on locale.

neutralboy commented 6 years ago

I resolved the error by placing markdownx url include above the ' ' url string.

urlpatterns = [
    path('admin/', admin.site.urls),
    path('API/', include('backend.urls')),
    re_path(r'^markdownx/', include('markdownx.urls')),
# Markdown above the empty url string
    path('', include('frontend.urls'))
]
HBarotov commented 3 months ago

Yeah, @eriktelepovsky was right. In my website, I used i18n to localize. We need to add the urls outside the i18n_patterns()

Incorrect:

urlpatterns = i18n_patterns(
    path("admin/", admin.site.urls),
    path("markdownx/", include("markdownx.urls")),
    path("rosetta/", include("rosetta.urls")),
    ...
)

Correct:

urlpatterns = i18n_patterns(
    path("admin/", admin.site.urls),
    # Translations
    path("rosetta/", include("rosetta.urls")),
    ...
)

urlpatterns += [
    path("markdownx/", include("markdownx.urls")),
]

As of this writing in 2024, I could not find relevant documentation. I think it would be a good idea to mention this in the documentation.