简体   繁体   中英

Error: NoReverseMatch when using render_model

I'm a newbie in django-cms and I'm trying to create a placeholder outside the cms. I created the model and inserted some dummy data to test. Then I created a template to display this model and checked if I was able to edit it in the frontend. Here's my HTML code where I'm getting an error:

{% load i18n staticfiles thumbnail cms_tags %}

<article class="article">

    <h2>
        {% render_model article "title" %}
    </h2>

    <p>{{ article.creation_date|date }}</p>

    {% if detail_view %}
        {% render_placeholder article.content language placeholder_language %}
    {% endif %}
</article>

The error I'm getting is this:

NoReverseMatch at /en/news/
Reverse for 'cms_myapp_news_change' with arguments '(5L,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

And this error is hapening in the render_model line. (I've commented each line to check where exactly the exception occurs.)

I've added a url to my list to see if would work:

url(r'^news/(?P<pk>\d+)/$', login_required(v_index.news), name='news_change')

But still the exact same error.

Do you know what's hapenning?

EDIT:

Here's my model:

class News(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True)

    title = models.TextField(verbose_name=_(u'Title'), db_column='TITLE')

    description = models.TextField(verbose_name=_(u'Description'), db_column='DESCRIPTION')

    creation_date = models.DateTimeField(db_column='CREATION_DATE', verbose_name=_(u'Creation Date'), auto_now_add=True)

    content = PlaceholderField('news_content',
                               related_name='news_content')

    class Meta:
        app_label = 'cms_myapp'
        ordering = ['-creation_date']
        verbose_name = _(u'New')
        verbose_name_plural = _(u'News')

UPDATE:

I've tried to configure the admin part for this model so I added the file admin.py : (and removed the url posted above)

from cms.admin.placeholderadmin import FrontendEditableAdminMixin
from django.contrib import admin

from cms_myapp import models


class NewsAdmin(FrontendEditableAdminMixin,admin.ModelAdmin):
    frontend_editable_fields = ("title", "description")


admin.site.register(models.News, NewsAdmin)

But still I get the same error.

You have defined namespace 'news_change' but django tries to reverse on 'cms_myapp_news_change' ... Wherever reverse is happening try to make it look like this reverse('cms_myapp:news_change') .

Make sure 'cms_myapp' is registered in main project urls or cms_apps.py if it's loaded by an app.

Check models method get_absolute_url() or others which is trying to do this reverse.

This is just an example, check your reverse and registering namepsace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM