Django Tutorial for Beginners - 31 - ModelForm and CreateView

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

So judging from the comments I'm far from the only person here who isn't thrilled with the assumption that we've all learned bootstrap before. Most people I'd imagine are coming from python backgrounds that needed a web framework that minimizes HTML dependency. Assuming we know bootstrap is a little ridiculous.

For this tutorial I've limited the add_album form to just:

{% extends 'music/base.html' %}
{% block title %}Add a New Album{% endblock %}
{% block albums_active %}active{% endblock %}

{% block body %}
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save" />
</form>

{% endblock %}

i'll learn bootstrap another day, gotta make it to the end of these tutorials because I still love your teaching style.

DreamBigGoBig
Автор

hey! why did you jump up the tutoria at 10:42 video. we have not already created it.

RobertoCarlosMena
Автор

Hey Bucky,


How did form template has field values of album class. We haven't passed anywhere.

SaiKumar-toud
Автор

guys for django version 2 its from django.urls import reverse instead of from django.core.urlresolvers import reverse

lakshayjayant
Автор

I agree with the comments about bootstrap and having to know it....I think Bucky is the greatest but he should have told us that if you don't know bootstrap you should be familiar with it before going on to django....

jhecht
Автор

why does empty field generate error at 9:29? where is it configured?

supriadiyusuf
Автор

Hey bucky, u just showed how to create album but didn't show how to add song using form. What should we do to add song? Should we create another createSong class to add songs?? Then how do we send the albums primary key??

ibex
Автор

I do not understand why we're redirected to detail view (/music/6/) after clicking submit?

jasurbekfayziev
Автор

How do you make the form go in the middle instead of being aligned to the left? With html it's easy using margin but with Django forms, I'm having hard time moving it around and centering it

funbadult
Автор

Just a suggestion to all that are coming into this tutorial post this date, it would be great if you completed the polls tutorial in the django documentation and use buckys tutorials as reference as most of the stuff is deprecated. The principles are otherwise the same.

napoleonb
Автор

for those who don't know bootstrap. You don't need bootstrap for the forms, it works without a single bootstrap code. looks ok too

album_form.html (page that you create in template, add below code to the page no bootstrap needed)


{% extends 'music/base.html' %}
{% block title %}Add a New Album{% endblock %}


{% block body %}
<form action="" method="post"
{% csrf_token %}
{% include 'music/form-template.html' %}
<input type="submit"/>
</form>
{% endblock %}

form-template.html (page that you create in template, add below code to the page no bootstrap needed)

{% for field in form %}
{{ field.errors }}{{field.label_tag}}
{{ field }}
{% endfor %}



but do learn bootstrap its good and super easy. This is just so you learn this tutorial faster.

samnik
Автор

I am getting error while pressing submit button. 'Add album' is correctly showing the form. After clicking submit, I see database entry, but redirect is crashing. I debugged and found that template/music/detail.html is not as you have. Kindly help. Also thank for the tutorial

DeepakKumar-nljr
Автор

I had an error, that would show up in PyCharm pro, when I entered {{ field.errors }} and {{ field }} in the form template. The word 'field' would be orange/yellow, as if there was another parameter needed such as {{ url field.errors }} I also got the parsing error for this, in the browser. I did not get an error for {{field.label_tag}}
for some reason. So I landed up copy/pasting the exact thing '{{ field.errors }}' and '{{ field }}' over what I had, and it worked; no more errors.


My questions is: could this be a language setting, in my computer, causing this syntax error?

tonyiguru
Автор

Hey Bucky and community, I have been troubles with the base.html file. When I extends it the content of the anothers pages is not showing. Have an idea or a source code?? Thank you very much.

aaronaaronaaron
Автор

I think I have exactly the same code as you, Bucky, however when I click this submit button, i am not directed to the home page

ankushjindal
Автор

You have named the included generic form template "form-template" but if we have more models and need to create model forms then how will we name that included generic template?? We can't name these "form-template" because we alrady have one. And what wiil be in the for loop {% for field in form(what will be there?) %}.

ibex
Автор

couldn't understand how form is working when nothing defined in action,
and I am using a Date Field for release date, but its not showing me calender there. What to do ?

AmandeepSingh-kllv
Автор

I think I missed something, in which part did he set that when you click submit button it will take you to the details?

Hackaprende
Автор

Nice vid, but I have a question. How could i create a Instance of "Song" with a further Attribute (let's say "song_publisher) and set this Attribute via ForeignKey equal to the user who is currently logged in.

davidgromer
Автор

I don't want to loop / cannot loop over my fields. How do access single fields directly? Or do I need to write those in html?

kernel_cataclysm
join shbcf.ru