0
votes

I'm relatively new to django.. I'm trying to integrate the audiotracks package with my project. I'm trying to integrate the audiotracks package but I'm getting NoReverseMatch error. The documentation states..

Add audiotracks to your app ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Edit settings.py and add audiotracks to your list of INSTALLED_APPS. Then synchronize your database with::

$ python manage.py syncdb

Edit your ROOT_URLCONF_ and add a piece of code similar to::

urlpatterns += patterns('',
    # Here we mount the app under /music. Feel free to use something else
    url("^music", include("audiotracks.urls")),
    # Some URLs require a Django username
    url("^(?P<username>[\w\._-]+)/music", include("audiotracks.urls")),
)

Visit the URL /music/upload to upload your first track.

the error occurs when i try to access music/upload..

here's the full traceback.

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/music/upload

Django Version: 1.11.3
Python Version: 3.6.0
Installed Applications:
['account',
 'music',
 'audiotracks',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
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.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error: In template C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django_audiotracks-0.2.5-py3.6.egg\audiotracks\templates\audiotracks\base.html, error at line 25 Reverse for 'user_index' with arguments '('addemo1',)' not found. 2 pattern(s) tried: ['music/tracks/(?P\d)/?$', 'music/tracks$']

15 :       .errorlist { color: red; list-style: none; display: inline; }
   16 :     </style>
   17 :     {% block extra_head %}{% endblock %}
   18 :   </head>
   19 :   <body>
   20 :
   21 :   {% block subnav %}
   22 :       {% if user.is_authenticated %}
   23 :           <ul>
   24 :             <li><a href="{% url 'audiotracks' %}">{% trans 'Latest tracks' %}</a></li>
   25 :             <li><a href=" {% url 'user_index' user.username %} ">{% trans 'Your tracks' %}</a></li>
   26 :             <li><a href="{% url 'upload_track' %}">{% trans 'Upload track' %}</a></li>
   27 :           </ul>
   28 :       {% else %}
   29 :           &nbsp;
   30 :       {% endif %}
   31 :   {% endblock %}
   32 :
   33 :   {% if messages %}
   34 :   <ul class="messages">
   35 :     {% for message in messages %}

Traceback:

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner 41. response = get_response(request)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response 249. response = self._get_response(request)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view 23. return view_func(request, *args, **kwargs)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view 58. return view_func(*args, **kwargs)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django_audiotracks-0.2.5-py3.6.egg\audiotracks\views.py" in upload_track 109. return render(request, "audiotracks/new.html", {'form': form})

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\shortcuts.py" in render 30. content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader.py" in render_to_string 68. return template.render(context, request)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\backends\django.py" in render 66. return self.template.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render 207. return self._render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in _render 199. return self.nodelist.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render 990. bit = node.render_annotated(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render_annotated 957. return self.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py" in render 177. return compiled_parent._render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in _render 199. return self.nodelist.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render 990. bit = node.render_annotated(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render_annotated 957. return self.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py" in render 72. result = block.nodelist.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render 990. bit = node.render_annotated(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render_annotated 957. return self.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\defaulttags.py" in render 322. return nodelist.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render 990. bit = node.render_annotated(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py" in render_annotated 957. return self.render(context)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\defaulttags.py" in render 458. url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\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:\Users\Alexander\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix 497. raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /music/upload Exception Value: Reverse for 'user_index' with arguments '('addemo1',)' not found. 2 pattern(s) tried: ['music/tracks/(?P\d)/?$', 'music/tracks$']

1
You cannot have followed that instruction; apart from anything else, patterns no longer exists in Django 1.11. Please show your full urls.py.Daniel Roseman
thanks for pointing that out.. i added the second url and it worked..@DanielRosemanIaMtheMcee

1 Answers

0
votes
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^account/', include('account.urls')),
    url(r'^music/', include('music.urls')),
    url(r'^music/', include('audiotracks.urls')),
    url(r'^(?P<username>[\w\._-]+)/music', include('audiotracks.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    urlpatterns += [
        url(r'^site_media/(?P<path>.*)$', serve, {
            'document_root': settings.MEDIA_ROOT
        })
    ]
    urlpatterns += staticfiles_urlpatterns()