Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Django Tutorial for Beginners 24 Favorite View Function

  • Django Tutorial
  • 2016-09-25
  • 105
Django Tutorial for Beginners   24   Favorite View Function
startedframeworkbeginnersintroductionwikiparttutorialrestdevelopmentadvancedscratchwindowslinux1.8webpythondjango1.9
  • ok logo

Скачать Django Tutorial for Beginners 24 Favorite View Function бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Django Tutorial for Beginners 24 Favorite View Function или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Django Tutorial for Beginners 24 Favorite View Function бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Django Tutorial for Beginners 24 Favorite View Function

More intensive courses : http://grow-book.blogspot.com/
Abstract video content

alright guys so right now whenever the user submits this form

what's going to happen is it's going to package up all of the data is going to

get whatever song they selected and it's going to send it to this URL music

favorite

so what is that URL what's going to go look in here the URLs directory and said

our it was the URL or view function for views . favorite

well let me hop over to views and I need to find a function called favorite so

that is the last piece of the puzzle that we're going to do write the

function to essentially handle all of the form data now since we're also

working with the song model instead of just album we need to import that right

at the top and let me just copy this views favorite making function called

favorite and it takes all the same stuff so again just like the detail view this

URL structure whenever we call this URL it also passes in the album ID pretty

sweet so we can actually copy this line of code to love copy and paste and let

me get myself some more space to work alright may all right so we already have

the album ID but now what we need to do is we actually need to make sure that we

have a valid song ID so whatever song its past then we're going to query the

database and say for this song set is favorite equal to true however if that

song doesn't exist

maybe they're just didn't select anything or try to like her website or

something then that's we're going to say ok instead of just favoring a song send

back an error message

so that's all we're doing so make a try statement involves we first need to get

the idea of the selected songs so I'm just going to store that in variable

called selective song set equal to album . song set . gets in PK equals

post song alright so how do we get the idea of whatever song they selected well

whenever we made this form right here

what if that is a loop through every single song so for each song it set the

value of it to the song ID so what we're doing right here is you're saying get

the value of whatever song they selected so this is going to be able to something

like 12 $YEAR 10 14 whatever so we took the value or idea of the song and it's

now stored in selected song as long as they didn't do anything stupid all right

so that's all we have to do in the trace a statement or the triblock I guess is

calling now we need to handle exceptions so if you can't select the valid ID

maybe i don't know like i said they didn't select anything or they're trying

to pack our website for whatever reason if the idea is not valid then error

messages that returns is key error or song does not exist so what we want to

do in this case well we still want to redirect them back to this template but

now what we want to do is we want to include an error message so whatever we

write in the error message is going to pop up at the top

re so return render and we want to copy this now just do it by hand art recur

return render request and just remember we're just sending them back to the

details page but instead of just sending them back with no information what we

want to do is this actually I can just go ahead and copy this whole thing i'll

show you guys the easy way

so basically just gonna send them to that details page by instead of just

sending them album information we also want to include an error message like

this

error message and what can we say in their message just say uh you did not

select any song a valid on that might be a little bit better

all right looking good so hopefully they don't get that but if they do and there

you go

so the last chunk of the puzzle is just else statement and this is if everything

goes fine

so if we get air then it's just going to return the function right now so if we

get to this part of code we know that everything is going smoothly so you

remember how to update the database to pretty much just change something

well what you do is you just take selected song and changes attribute to

is favorite to true and also remember that I said anytime you actually want to

make sure you save the data to the database you need to explicitly called

the save function so this just change that repeating this actually stores your

changes in the database so you know what we can do is this man way too convenient

art so there you go

if everything went smoothly then we're just going to return them to this page

and hopefully now that the song is favorite they're going to see a star

right next with and check it out

so this is the form right here and in case you guys that know what i was

talking about this input is essentially this button and the label is this

section of it right here

...

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]