1

Installation was successful, forums and topics are fine, but there is a problem - if I post a topic with Unicode characters (e.g. Russian), there NoReverseMatch:

NoReverseMatch at /forum/
Reverse for 'forum' with arguments '('', 6)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['forum/forum/(?P<slug>[\\w-]+)-(?P<pk>\\d+)/$']

I understand that the problem of encoding. The problem is that I just do not know which file and how to edit to correct the error. For example, it is necessary to put prsto # - * - coding: utf-8 - * -. But where?

Request Method: GET
Request URL: http://127.0.0.1:8000/forum/

Django Version: 1.10.2
Python Version: 3.4.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'main_site',
 'ckeditor',
 'ckeditor_uploader',
 'mptt',
 'haystack',
 'widget_tweaks',
 'machina',
 'machina.apps.forum',
 'machina.apps.forum_conversation',
 'machina.apps.forum_conversation.forum_attachments',
 'machina.apps.forum_conversation.forum_polls',
 'machina.apps.forum_feeds',
 'machina.apps.forum_moderation',
 'machina.apps.forum_search',
 'machina.apps.forum_tracking',
 'machina.apps.forum_member',
 'machina.apps.forum_permission']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'machina.apps.forum_permission.middleware.ForumPermissionMiddleware']


Template error:
In template C:\Python34\lib\site-packages\machina\templates\machina\forum\index.html, error at line 0
   Reverse for 'forum' with arguments '('', 7)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['forum/forum/(?P<slug>[\\w-]+)-(?P<pk>\\d+)/$']   1 : {% extends 'board_base.html' %}
   2 : {% load i18n %}
   3 : {% load mptt_tags %}
   4 : {% load forum_tags %}
   5 : 
   6 : {% block sub_title %}{% trans "Index" %}{% endblock sub_title %}
   7 : 
   8 : {% block content %}
   9 :  <br />
   10 :     <div class="row">


Traceback:

File "C:\Python34\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response
  215.                 response = response.render()

File "C:\Python34\lib\site-packages\django\template\response.py" in render
  109.             self.content = self.rendered_content

File "C:\Python34\lib\site-packages\django\template\response.py" in rendered_content
  86.         content = template.render(context, self._request)

File "C:\Python34\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\library.py" in render
  245.         return t.render(new_context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  210.                 return self._render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\mptt\templatetags\mptt_tags.py" in render
  260.         bits = [self._render_node(context, node) for node in roots]

File "C:\Python34\lib\site-packages\mptt\templatetags\mptt_tags.py" in <listcomp>
  260.         bits = [self._render_node(context, node) for node in roots]

File "C:\Python34\lib\site-packages\mptt\templatetags\mptt_tags.py" in _render_node
  253.         rendered = self.template_nodes.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python34\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python34\lib\site-packages\django\template\defaulttags.py" in render
  439.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Python34\lib\site-packages\django\urls\base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "C:\Python34\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  392.             (lookup_view_s, args, kwargs, len(patterns), patterns)

Exception Type: NoReverseMatch at /forum/
Exception Value: Reverse for 'forum' with arguments '('', 7)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['forum/forum/(?P<slug>[\\w-]+)-(?P<pk>\\d+)/$']
payne
  • 13,833
  • 5
  • 42
  • 49
Антон Игин
  • 195
  • 1
  • 1
  • 12

1 Answers1

1

It's a bug in django-machina. With Unicode symbols in Forum names there are empty slug fields generated that results in NoReverseMatch exception.

Look at the code here /machina/apps/forum/abstract_models.py

class AbstractForum(MPTTModel, DatedModel):
...
    def save(self, *args, **kwargs):
        ...
        # Update the slug field
        self.slug = slugify(force_text(self.name))
        ...

Here is the slugify definition:

def slugify(value, allow_unicode=False):
    ...

Quick fix. Update save() method implementation like below and resave all your forums in admin.

self.slug = slugify(force_text(self.name), allow_unicode=True)

This fix was tested.

Dmitry Shilyaev
  • 713
  • 4
  • 10
  • I have that url: url(r'^forum/', include(board.urls)). Where i need add 'u'? Instead of 'r'? – Антон Игин Feb 03 '17 at 03:57
  • if this does not help, provide more code, to be able to reproduce this issue. – Dmitry Shilyaev Feb 03 '17 at 04:37
  • Provide full urls definition and where you use 'url' tag in your template. – Dmitry Shilyaev Feb 03 '17 at 05:29
  • urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^forum/', include(board.urls)), url(r'^ckeditor/', include('ckeditor_uploader.urls')), url(r'', include('main_site.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) I dont use url in templates yet. There is address: http://127.0.0.1:8000/forum/ – Антон Игин Feb 03 '17 at 06:07
  • The error comes from mptt_tags.py. Try remove u'' and add "from _ _ future _ _ import unicode_literals" in all urls.py. And also try (?P[\\w-]*) maybe you have empty slug on some node? Hope this helps. – Dmitry Shilyaev Feb 03 '17 at 06:49
  • I add import and change the url: url(r'^forum/(?P[\\w-]*)', include(board.urls)), That's not help. You can try yourself and install forum on your localhost. There is documentation: http://django-machina.readthedocs.io/en/latest/ – Антон Игин Feb 03 '17 at 09:11
  • Updated my answer after some debug. – Dmitry Shilyaev Feb 03 '17 at 20:25
  • Have you tried it? Mark answer as the solution if it works for you. Thanks. – Dmitry Shilyaev Feb 06 '17 at 06:55
  • Thanks, but that is not help me. i edit files in Python34/Libs/.../forum/abstract_models.py. I must create git clone in base dir? – Антон Игин Feb 06 '17 at 10:07
  • I tried to change the data in the git-clone in the project root, and the package in the site-packages, but neither one nor the other did not produce results. I need no install vanilla or demo-version? Because if so, then there is a problem with the installation of Doctor Compost and virtualwrapper - do as instructed, but there are errors. Maybe, that's happen becase i use the Windows? Loading project pythonanywhere.com and changed in the operating virtual environment specified string in the package, but it did not help. In any case, a sincere thank you for taking the time to my problem. – Антон Игин Feb 06 '17 at 12:20
  • Just post bug to django-machina project. To quickly fix it, you need to edit django-machina package files in place, as i did. Sorry, don't know where are they on Windows. You don't need to git clone anything, just edit already installed scripts. – Dmitry Shilyaev Feb 06 '17 at 14:11