Tutorial building index template

I spent a day trying to overcome the "NoReverseMatch at /polls/ is not a registered namespace error. Seems to have been problem in the Django site code for at least 5 years. I don’t understand why someone just doesn’t go in and fix it. Lots of opinions is Stackoverflow and other places but one solution finally worked. The next problem was another typo from me which I found and fixed. Now I seem to be at another tutorial error which does not have good explanations here, there, or anywhere. " _revers_with_prefix() argument after * must be an iterable not in. Well, I found the answer to that error in the tutorial and now I am at the next one—‘polls.results’ is not a valid view function or pattern name. I will try to solve this. If you feel disposed to lend a hand, great. But I have a deeper question. This tutorial is sort of great, but why doesn’t somebody just go in and clean it up. Somebody put a lot of work into building, why would they want to clean it up? I damn sure would. If I had the access, I would do it myself.

Well, there is another problem. This one is on me…Geez…

Well, at least I keep trying. I’ll bet for every real tutorial error there are a thousand user, like me, errors.

Truth of the matter is that although this gets increasingly frustrating it also gets increasingly amusing and rewarding.

Also, there is this guy at Real Python, Martin Breuss, who preaches and preaches about “error messages are your friend” and the more I carefully read error messages the more I am convinced that he has a good message.

I’m not sure what error you think there is in the tutorial - my experience has been that every issue that someone has had with the tutorial is either a missed step or a typo.

That’s not to say that there isn’t a problem - but as a public site, with the code out on github, anyone can submit a pull request with a correction to any errors that may exist.

On a side note, I’d be extremely wary about any answers found on StackOverflow. The biggest problem is that the answers aren’t kept up to date as Django continues to evolve and improve, and so the answers you find out there become increasingly sub-optimal or problematic in their own right. (Especially if they don’t specify what version of Django that the answer applies to - there have been many significant changes since, say, 1.8.)

Ken

Well, I am very happy to read this. I would have to go through all my cries for help to find that one error and, frankly, while I believe it is there I am quite happy to know that you don’t believe it. Probably, the most significant thing that I am getting out of all this is an awareness of how many mistakes I make and how to get better at finding them. I am quite impressed with your patience with me, and I am sure many others. It really is the only way we will learn even though they are our mistakes. I wonder, what is you connection to Django? I wish I were good enough to help. I have actually built many websites by using templates and modifying them. I have a great idea for a website I want to build if I can really learn this. Thanks, again. I now have an error I am trying to run down late in lesson 4, “‘polls.views’ has no attribute 'DetailView.” Cheers.

I thought I was successfully through “4” and then this happened. I can’t find the appropriate location for this page in the tutorial and I am going to start from the beginning. But. Can you just quickly see what’s wrong here? I get a message—“Error during template loading. Reverse for detail not found, ‘detail’ is not a valid view or function name.” I think I have seen this before.

<html lang="en">
<head>
   <meta charset="UTF-8">
  <title>Polls Index</title>
</head>
<body>

{%  if latest_question_list  %}
    <ul>
        {% for question in latest_question_list %}
                <li><a href="{% url 'detail' question_id %}">{{question.question.text}} </a></li>
        {% endfor %}
   </ul>
{% else %}
    <p>No polls are available, say Charlotte</p>
{% endif %}
</body>
</html>

I know I have seen this before and I will try to hunt it down. If you could point me in the right direction, that would be great, but I will be looking. The line starting with

  • <a href… is where the error seems to be.

    Cheers. Ralph

    In proof reading I realized that the previous time I had question.id instead of question_id

  • Hmmm. In part 4, there is no modification to the index.html page.

    The issue would be with your urls.py file. Earlier on page 4, in the Amend URL section, you’re to make your urls.py file look like this:

    from django.urls import path
    
    from . import views
    
    app_name = 'polls'
    urlpatterns = [
        path('', views.IndexView.as_view(), name='index'),
        path('<int:pk>/', views.DetailView.as_view(), name='detail'),
        path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
        path('<int:question_id>/vote/', views.vote, name='vote'),
    ]
    

    The second entry is where the name ‘detail’ is assigned to your view. Any error here would affect the rendering of your template.

    Ken

    Well, that is exactly how my code looks. I have examined it many times to make sure, especially the second “path.” In the file structure, there is polls/templates/polls/detail.html I don’t know where else to look.

    Well, I went to look at the “detail.html” which should be polls/detail and it looks nothing like what the error message says. The error message looks like the old version of this page, so I am going to have to retrace my steps. Hmmph.

    I’m not sure how much this will help, but a lesson that I learned the hard way in college was to make very small steps when building software.

    If your feedback loop is a) make a small change to the code then b) test the small change, I think that isolating problems becomes easier. In that mode, there is less that could have changed. If the app was working and you introduce a small change that makes it break, then it’s generally safe to conclude that the small change caused the breakage.

    I still use this pattern today to help me develop quickly. It’s the “Slow is smooth, smooth is fast” concept applied to software.

    I guess that doesn’t really help you get our of your current error, but it may help in the future.

    To really make good use of the concept, devs can also apply version control (like Git) to create safe checkpoints. Learning a little bit of Git and throwing away changes when things get really broken is also a strategy that has saved me many times.

    First of all, thank you. I truly understand what you are saying and
    believe or not, it’s a lesson that I have learned and try to guide
    myself by. Typically. I always make sure something works before I move
    on. Many times I have tried to run something before I have implemented
    subsequent instruction and then my code wasn’t ready.

    What generally happens when I hit a snag is that I try and try to find
    the error. I go over the code several times and I read over the text.
    I also read the error messages as carefully as I can and that probably
    is what helps the most.

    When I simply cannot figure it out, I try to get help. Ken Whitesell
    has been great. The people at Real Python, no so much. Martin Breuss
    has been helpful at times and so has David Amos. Still, especially at
    RP, there is occasionally an error on their part but most of the time
    it’s a stupid typo that I just can’t see. Ken tells me there are no
    errors in the code around the “polls” application from the Django
    Foundation. It’s really good to know that he believes that. I thought
    I had found one, but only once did it really seem like it. Every other
    time, we, me or Ken, found my mistake.

    Finding my mistakes usually turns out to be fun. Didn’t used to be that
    way, but I am getting better at it and that’s rewarding.

    So, I believe what you say and I try to follow your advice. I
    appreciate your offering it.

    Cheers.

    Ralph Barhydt

    BTW, you might be interested in knowing that in recent times I have
    discovered I make far, far more typos and simple errors than I ever
    dreamed of. I pay attention to that.

    1 Like

    That’s great to hear. I wish you luck on your journey. For all its occasional frustrations, I find programming to be extremely rewarding, and I hope you experience that same joy and reward.

    1 Like

    I appreciate the kind words - but in the interests of being accurate, I’d like to say that I’m not saying there are no (or can’t be) any errors - but just that, given the visibility of that portion of the site and the number of eyes reviewing it with every new release, my experience is that errors don’t last long before being corrected.

    (And, if an error is found, anyone can submit a pull-request with the fix)

    Anyway, I’m just one of many who are here to help. I learned a long time ago that “Come for the code, stay for the community” really means something here.

    Ken

    Is “here” a virtual place or is it a real, physical location. Is the
    organization the Django Foundation. The guys in Lawrence, KS, who
    designed this thing and built it still around. Rock chalk, Jayhawk?

    Purely virtual - my generic reference of “here” is to all the people on-line and in person in all the various forms (github, this forum, the mailing lists, bloggers, twitter, conferences, meet-ups, etc) who donate their time and energy to make Django the product it is today. I’m just one of many.
    (I don’t even think that any of the original founders would even know who I am if they ran into me in person - and I’m ok with that.)

    Ken

    That is fascinating, almost surreal. I came out of the Army as an
    officer and joined IBM. Hierarchy and structure deeply embedded. The
    formlessness of all this is difficult for me to comprehend. Your
    helpfulness and kindness is actually what I am used to. To me, Stock
    Overflow is an anathema — half-ass answers, arrogance, wrong answers
    and misinterpreted questions. To me, you are a different and welcome beast.

    I am very impressed with Django and, of course, with Python. I was
    introduced to Fortran, Cobol, and RPG. RPG was the first language that
    tried to be “easy” and user friendly. Django and Python have come a
    long way and I like them.

    Thanks again for your help.

    Best wishes.

    Ralph