Django Tutorial for Beginners – 16 – Raising a 404 HTTP Error

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


Posted

in

by

Tags:

Comments

31 responses to “Django Tutorial for Beginners – 16 – Raising a 404 HTTP Error”

  1. NoobAcademy Avatar

    When i click on the names of the albums in /music/ im getting a blank page, no error just nothing.

  2. Ramisa Anjum Aditi Avatar

    I made a little typo in my models.py file and as a result I got an error . But when I fixed that, the error didn't disappear after refreshing the page. I had to restart my server to fix it.
    Does that mean I need to restart my server every time I make a change in the code of models.py?

  3. Viet Blogger Avatar

    Thanks so much :D.

  4. aleks0403 Avatar

    Regarding simple database query and giving httpresponse you should also have a look at generic views!

  5. roger smith Avatar

    Django tutorial 16 Raising a 404 HTTP Error
    apps used in this tutorial

    musictemplatesmusicindex.html
    musictemplatesmusicviews.html

    musicviews .py

  6. Mohammed Noor Avatar

    I just started learning Django and Im using Django 2.0. I haven't found any tutorials of such good quality for Django 2.0 yet. If anyone has then please let me know. Having said that, I must add, this is the best channel to learn programming!

  7. yaykaboom Avatar

    If you guys get an error saying "ValueError at Music/1" Make sure that your indentations are exactly the same in the video! I never knew that indentations affect your code in python.

  8. Farida M Avatar

    Hi I'm just starting Django and following the tutorials and I have the following problem right now:
    under " Here are all my albums: " the page does show the albums but calls them album.album_title instead of the actual album title..
    can someone help??

  9. Immerse Your Senses Avatar

    Getting error:

    Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
    ^admin/
    ^music/ ^$ [name='index']
    ^music/ ^/(?P<album_id>[0-9]+)/$ [name='detail']
    The current path, music/2, didn't match any of these

    please assist!

  10. Markus Scheucher Avatar

    can't you put the all_albums, context variables one scope tier higher so that you can use it in all models?

  11. YOYO YO Avatar

    Thank you so much Bucky youre awesome!

  12. Miles Rose Avatar

    While following along and testing the code, I've never been so relieved to actually see a 404 message 😀

  13. Ja Cre Avatar

    Silly question here perhaps but what "language" or mark up is the {%%} tag defined as? I am trying to get pyCharm to recognise it for the "inject language or reference" feature to work.

  14. Alex Drozd Avatar

    How does it know to only display the album name and the band name? album = Album.objects.get(id=album_id) looks like it would get all the objects to me.

  15. Bobsley Avatar

    Why can't I simply use SQL queries? What for is there that all bells and whistles? Could you explain this?

  16. Peter Muchina Avatar

    For Django 11 you might have to modify the detail function in views.py in the Music app while getting the album via id/pk from
    “`album = Album.objects.filter(id=album_id) TO album = Album.objects.filter(id=album_id).get()“`

  17. Almaral Engineering Avatar

    Hi, I am getting Unresolved attribute reference 'DoesNotExist' for class 'Album', the same when I write Album.objects.all()

  18. greddee Avatar

    This might be mentioned further on but you can also import get_object_or_404 from django.shortcuts and use the following:
    def detail(request, album_id):
    album = get_object_or_404(Album, pk=album_id)
    return render(request, 'music/detail.html', {'album':album})

    get_object_or_404 basically does exactly the same as the try-except thing.

  19. alfritz sd Avatar

    im having hard time on tab error and indent (on python) while having your tutorial.

  20. mohana krishnan Avatar

    Hi… I would like to say 'Thank You' through this comment. Your Tutorial really helps me in getting my project created. Very detailed view of presenting the information and not too lengthy tutorials. It helps to pay attention to the videos fully. Was able to relate things and make my work to progress further. Thanks again.

  21. Asifuzzaman Bappy Avatar

    {{ album }} in detail.html does not work!!!!!
    its showing error – bad operand type for unary +: 'unicode'
    This si what the pyCharm terminal says about this problem GET /music/1/ HTTP/1.1" 200 0
    Also when I goto my /music it shows I dont have any Albums!!!!!

    when i go to that music/1 or music/2 it shows nothing and in console it shows error. Im using pyCharm as well.
    please help anyone.

  22. Pratham Tangri Avatar

    Why doesn't line 18 run when except block runs? The command should come to it after the except block too, should't it?

  23. Ramesh Patil Avatar

    You don't have any albumsPyCharm not recognized Python code inside an html file even after templating in {% %}?is it dependent on pycharm version?

  24. daniel nuñez Avatar

    hi all 🙂 i get a error ;S i cant solve it, it say that detail() got an unexpected keyword argument 'Noticia_id' i have done some changes but it is the same code jeje just testing it an learnig what it can be ?

    this is my views

    def index(request):
    user= Usuario.objects.all()
    return render(request,'users/index.html',{'user': user})

    def detail(request, usuario):
    try:
    users=Usuario.objects.get(usuario)
    except Usuario.DoesNotExist:
    raise Http404("Usuario no existe")
    return render('users/detail.html', request, {'users':users})

    i have users in db and i can show then but when i click on then it gave me tha error :s and the urls are :

    #/usuarios/
    url(r'^$',views.index,name='Usuario'),

    #/usuarios/noticia-id/
    url(r'^Noticia-(?P<Noticia_id>[0-9]+)/$',views.detail,name='detail'),

    ill wait for your help thanks 🙂

  25. Itz Owen-J! Avatar

    still getting no "you dont have any albums"

  26. Harry Teran Avatar

    if bucky does not show all his changes cause some people follow him step by step :
    Just in case:

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

    here it is solved (check the f*king slash!):

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

  27. jakkam girish Avatar

    NOT NULL constraint failed: music_song.album_title_id
    getting the error when i do song.save()

  28. jarmadax Avatar

    What is that Album.DoesNotExist? Where is it defined? In the Model? You do not show that in the tutorial. Replacing that line with except Exception: fixes it.

  29. Omar Abdul-Hafez Avatar

    I have a quick question:

    How do you make PyCharm recognize Python code even inside an html file and code?

    Or is this part of the paid full-fledged version only?

    Thanks. 🙂

  30. Rich Zhu Avatar

    Hi, I'm a student at Carnegie Mellon and your video on django has really helped me learn the tool a lot better. Thank you for making such wonderful videos and I can't wait to see more of them.

Leave a Reply

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