0

So I have recently started learning Django, after finishing the tutorial I decided to create my own website and have run into an error that I honestly just don't understand.

The error is:


Error during template rendering

In template /home/phil/Projects/mysite/homepage/templates/_partial.html, error at line 13 Reverse for 'bio' with no arguments not found. 1 pattern(s) tried: ['$bio/']


homepage/templates/_partial.html

<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
  <div class="navbar-nav">
     <a class="nav-item nav-link active" href="{% url 'home:index' 
              %}">Home <span class="sr-only">(current)</span></a>
     <a class="nav-item nav-link" href="{% url 'home:bio' %}">Bio</a> <!--Attention-->
     <a class="nav-item nav-link disabled" href="{% url 'home:index' 
              %}">Technologies</a>
  </div>
</div>

homepage/url.py

from django.views import generic
class IndexView(generic.ListView) : 
    template_name = 'homepage/index.html'


class BioView(generic.ListView) : 
    template_name = 'homepage/bio.html'

homepage/urls.py

from django.conf.urls import url
from . import views
app_name = 'home'
urlpatterns = [
       url(r'^$', views.IndexView.as_view(), name='index'),
       url(r'^bio/', views.BioView.as_view(), name='bio'),
       url(r'^skills/', views.SkillsView.as_view(), name='skills'),
       ]

app/urls.py

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

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

As I said I had followed the Django tutorial and honestly can't see what the error is. Index works as expected, but when I call bio or skills it throws this exception.

Edit: adding requested views. :(

  • 1
    Show the main urls.py. – Daniel Roseman Aug 30 '17 at 21:38
  • Where's the url with the pattern `$bio/` ? A `$` should be at the end of a regular expression, not the start. – Håken Lid Aug 30 '17 at 21:38
  • @Haken it's because op is probably including home.urls with a prefix ending in $. Which is why we need to see the main URLs. – Daniel Roseman Aug 30 '17 at 21:42
  • You probably forgot to set the `home` namespace when including `homepage.urls` in the main `urls.py`. – Paulo Scardine Aug 30 '17 at 21:43
  • Is your views file really called `homepage/url.py`? But you are importing your views from `views` in `urls.py` – Håken Lid Aug 30 '17 at 21:44
  • Sorry for the late response, ok in order quickly, I don't have a main.py this shares the same directory structure as the tutorial does so if there is a main.py equivalent I could provide I will. I have added the app/urls.py to the question as well if I understand @HåkenLid request properly. Finally the tutorial asks for it this way, if you have a suggestion or feel like there is a better way feel free to pm me. – Phillyp Henning Aug 31 '17 at 15:48
  • Your bug is caused by what is explained in the linked duplicate question. When you use `include` with URL routes, you must not end the regex with `$`. Just remove the $ in the two first urlpatterns in app/urls.py – Håken Lid Aug 31 '17 at 19:42

1 Answers1

0

If you use a name, you can call that name directly in the url, so:

{% url bio %}

Instead of:

{% url name:bio %}

Here's a link: https://docs.djangoproject.com/en/1.11/topics/http/urls/#url-namespaces-and-included-urlconfs.

David542
  • 104,438
  • 178
  • 489
  • 842