0
votes

I am new to python and Django and use win10 system.

Django Version:1.9.4. and Python Version:3.6.3.

In template D:\Music\music\templates\music\index.html, error at line 29

19                        <div class="caption">
20                            <h2>{{ album.album_title }}</h2>
21                            <h4>{{ album.artist }}</h4>
22
23                            <!-- View Details -->
24                            <a href="{% url 'detail' album.id %}" class="btn btn-primary btn-sm" role="button">View Details</a>
25
26                            <!-- Delete Album -->
27                            <form action="{% url 'delete_album' album.id %}" method="post" style="display: inline;">    Traceback:

File "D:\Python\lib\site-packages\django\template\defaulttags.py" in render
  507.                               current_app=current_app)

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in reverse
  600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
  508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

During handling of the above exception (Reverse for 'website.index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []), another exception occurred:

File "D:\Python\lib\site-packages\django\core\handlers\base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "D:\Python\lib\site-packages\django\core\handlers\base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "D:\Music\music\views.py" in index
  145.             return render(request, 'music/index.html', {'albums': albums})

File "D:\Python\lib\site-packages\django\shortcuts.py" in render
  67.             template_name, context, request=request, using=using)

File "D:\Python\lib\site-packages\django\template\loader.py" in render_to_string
  97.         return template.render(context, request)

File "D:\Python\lib\site-packages\django\template\backends\django.py" in render
  95.             return self.template.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render
  206.                     return self._render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in _render
  197.         return self.nodelist.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render
  992.                 bit = node.render_annotated(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render_annotated
  959.             return self.render(context)

File "D:\Python\lib\site-packages\django\template\loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in _render
  197.         return self.nodelist.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render
  992.                 bit = node.render_annotated(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render_annotated
  959.             return self.render(context)

File "D:\Python\lib\site-packages\django\template\defaulttags.py" in render
  513.                         six.reraise(*exc_info)

File "D:\Python\lib\site-packages\django\utils\six.py" in reraise
  686.         raise value

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

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in reverse
  600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
  508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /
Exception Value: Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
28                                {% csrf_token %}
29                                <input type="hidden" name="album_id" value="{{ album.id }}" />
30                                <button type="submit" class="btn btn-default btn-sm">
31                                    <span class="glyphicon glyphicon-trash"></span>
32                                </button>
33                            </form>
34
35                            <!-- Favorite Album -->
36                            <a href="{% url 'favorite_album' album.id %}" class="btn btn-default btn-sm btn-favorite" role="button">
37                                <span class="glyphicon glyphicon-star {% if album.is_favorite %}active{% endif %}"></span>
38                            </a>

It's the error traceback:

File "D:\Python\lib\site-packages\django\template\defaulttags.py" in render 507. current_app=current_app)

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in reverse 600. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix 508. (lookup_view_s, args, kwargs, len(patterns), patterns))

During handling of the above exception (Reverse for 'website.index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []), another exception occurred:

File "D:\Python\lib\site-packages\django\core\handlers\base.py" in get_response 149. response = self.process_exception_by_middleware(e, request)

File "D:\Python\lib\site-packages\django\core\handlers\base.py" in get_response 147. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "D:\Music\music\views.py" in index 145. return render(request, 'music/index.html', {'albums': albums})

File "D:\Python\lib\site-packages\django\shortcuts.py" in render 67. template_name, context, request=request, using=using)

File "D:\Python\lib\site-packages\django\template\loader.py" in render_to_string 97. return template.render(context, request)

File "D:\Python\lib\site-packages\django\template\backends\django.py" in render 95. return self.template.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render 206. return self._render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in _render 197. return self.nodelist.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render 992. bit = node.render_annotated(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render_annotated 959. return self.render(context)

File "D:\Python\lib\site-packages\django\template\loader_tags.py" in render 173. return compiled_parent._render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in _render 197. return self.nodelist.render(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render 992. bit = node.render_annotated(context)

File "D:\Python\lib\site-packages\django\template\base.py" in render_annotated 959. return self.render(context)

File "D:\Python\lib\site-packages\django\template\defaulttags.py" in render 513. six.reraise(*exc_info)

File "D:\Python\lib\site-packages\django\utils\six.py" in reraise 686. raise value

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

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in reverse 600. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\Python\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix 508. (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /

Exception Value: Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

It's my music\urls.py:

from django.conf.urls import url
from . import views

app_name = 'music'

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^register/$', views.register, name='register'),
    url(r'^login_user/$', views.login_user, name='login_user'),
    url(r'^logout_user/$', views.logout_user, name='logout_user'),
    url(r'^(?P<album_id>[0-9]+)/$', views.detail, name='detail'),
    url(r'^(?P<song_id>[0-9]+)/favorite/$', views.favorite, name='favorite'),
    url(r'^songs/(?P<filter_by>[a-zA_Z]+)/$', views.songs, name='songs'),
    url(r'^create_album/$', views.create_album, name='create_album'),
    url(r'^(?P<album_id>[0-9]+)/create_song/$', views.create_song, name='create_song'),
    url(r'^(?P<album_id>[0-9]+)/delete_song/(?P<song_id>[0-9]+)/$', views.delete_song, name='delete_song'),
    url(r'^(?P<album_id>[0-9]+)/favorite_album/$', views.favorite_album, name='favorite_album'),
    url(r'^(?P<album_id>[0-9]+)/delete_album/$', views.delete_album, name='delete_album'),
]

urls.py:

from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^music/', include('music.urls'),),
    url(r'^', include('music.urls')),
]

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

How to solve this problem?

2
Can you paste the error traceback ? It is unclear that where the call has happened.Sandeep Balagopal
Can you clarify what's going on with the last two urlpatterns? Why do both r'^music/' and r'^' use include('music.urls')? This isn't strictly wrong, it just seems strange/possibly redundantubadub
@SandeepBalagopal Thanks for your help, I have pasted the error traceback.shirley Xia
I'm new to python and Django, just follow the Youtube tourial... Should I remove one of them? @ubadubshirley Xia

2 Answers

1
votes

Namespace your music apps urls in main urls.py as:

url(r'^music/', include('music.urls'), namespace="music"),

Remove the trailing slashes from your url patterns if you have not handled that in settings for slash config

url(r'^(?P<album_id>[0-9]+)$', views.detail, name='detail'),

You can refer to these named url patterns in template as follows:

{% url 'music:detail' album.id %}
0
votes

You are calling website.index somewhere. change it to music:index where music is the app_name and index is the url name.