Django Tutorial for Beginners – 21 – Namespace and HTTP 404 Shortcut

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

30 responses to “Django Tutorial for Beginners – 21 – Namespace and HTTP 404 Shortcut”

  1. Ramisa Anjum Aditi Avatar

    How can we pass a string or an error message with get_object_or_404() function? If we can't , then using try-except might be better .

  2. roger smith Avatar

    Django tutorial 21 Namespace and HTTP 404 Shortcut
    apps used in this tutorial

    musictemplatesmusicindex.html

    musicurls .py
    musicviews .py

  3. adarsh kadameri Avatar

    Edit the main urls.py file and add namespace attribute like this :

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

    otherwise application won't work

  4. idriis yusuf Avatar

    I am getting only the image in details page after putting this on the detail function in view.py
    from django.shortcuts import render, get_list_or_404
    def detail(request, album_id):
    album = get_list_or_404(Album, pk=album_id)
    return render(request, "music/detail.html", {"album": album})

  5. Kojak Eugenio Avatar

    I am getting blank details page after putting this on the detail def

    album = get_list_or_404(Album, pk=album_id)
    return render(request, "music/detail.html", {"album": album})

  6. Charles wood Avatar

    Wow, it makes a whole lot more sense now why you make a url file in each app. Thanks Bucky!

  7. SONIKA JHA Avatar

    since the index.html belongs to music app then shouldn't the link to details seek out for the music app's details without even mentioning the namespace?? But if so happens then the need for namespace shouldn't arise.

  8. RENATO LACERDA Avatar

    do you have any rails tutorial?

  9. Mike Zhang Avatar

    I followed the tutorial and get the error that Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'music/(?P<album_id>[0-9]+)/$']. Does anyone know how to fix that?

  10. 3636 6969 Avatar

    Your Tutorials are very clear and anyone can learn Python. Thank you very much. Good for new gen.

  11. Twinky Game Avatar

    dude,I need you source codes from where can i get them?
    can't find this tutorial's on GitHub

  12. David Castro Avatar

    dude you are AWESOME, the best videos ever ! thanks!

  13. Ramesh Patil Avatar

    <li><a href = "{% url 'music:detail' album_id %}">{{album.album_title}}</a></li>
    the error is in this line

  14. Ramesh Patil Avatar

    i just followed the tutorial but after executing the code i got below error.
    Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'music/(?P<album_id>[0-9]+)/$']

  15. David Johns Avatar

    I'm using Django 1.10 and I am having a hard time with static_root as it seems to be pointing to Viberr/website/static. It should be Viberr/music/static. I cannot get style.css to work as it gives a 404. I have been going in circles for days trying to get this to work and even though I have gone over the tutorials several times, I must have missed something. I have downloaded the code and compared but still cannot see where I might have gone wrong. In fact this whole thing includes my media root as well.
    Could anyone provide any pointers?

  16. Erik L Avatar

    Very important – at 1:44 – use a COLON in between music:detail.
    Easy typo to get stuck on…

  17. Anushil Kumar Avatar

    >>> from music.models import Album, Song
    >>> a = Album.objects.get(id=1)
    >>> a.artist
    u'Taylor swift'

    why u is coming?

  18. Ratul Minhaz Avatar

    `app_name = 'music'` in music/urls.py does not work! only adding namespace in the project's urls.py works: `include('music.urls', namespace='music')`

  19. Mobus Dorphin Avatar

    This has been an excellent companion to the official django docs tutorial, though I would say if you're following that tutorial you should have kept the models the same i.e. polls instead of albums, would make it easier to code along. Anyhow, still a good companion video and I am learning, thanks!

  20. JulianACienfuegos Avatar

    very helpful thanks!

  21. Ishmeet Singh Avatar

    jango codes are hard to retain

  22. Theophilus Amaefuna Avatar

    I'm so new in anything programming, this is actually my first time and its been cool but I don't know what I'm getting wrong but the Http 404 shortcut isn't working for me

  23. James Njuguna Avatar

    good stuff Bucky

  24. Ryan Lindskog Avatar

    Does "get_object_or_404()" have a 404 message parameter?

  25. Daniel Jeffery Avatar

    I have not seen the app_name approach here as used in the music.urls, the way I have seen elsewhere is adding a namespace to the main urls.py when you include the link to music.urls

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

  26. Christopher Capio Avatar

    where did you get that album_id?

Leave a Reply

Your email address will not be published. Required fields are marked *