Re: How to fix: Django forms: {{ form }} is not working in a dynamic html page
Form should be provided in context render of index view . Try this please and let me know if it worked On Sunday, June 9, 2019, Marvelous Ikechi wrote: > I couldn't find a description field in the creation of your ContactForm. > Maybe it's an oversight from me. However, if it isn't, I'm not expecting to > see a {{card.description}} in your cards.html page. > > On 12:30PM, Fri, Jun 7, 2019 Delcy John wrote: > >> i think the error is in form.py,you must put indentation in class >> >> On Fri, Jun 7, 2019 at 9:37 AM Joe Reitman wrote: >> >>> Interesting problem. It won't display because the form is inside a >>> for-loop. Django Template language looks at variables inside a for-loop >>> differently. Basically it looks for a collection. Since {{ form }} is not a >>> collection, it just ignores it. >>> >>> I'm not sure how you can create multiple forms like that. But I would be >>> interested in knowing. >>> >>> >>> On Thursday, June 6, 2019 at 6:14:57 PM UTC-5, Majid Rafiee wrote: I've created a form in Django: #forms.py from django import forms class ContactForm(forms.Form): name = forms.CharField() number = forms.FloatField() eail_user = forms.EmailField() and imported in in views.py #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom cards.forms import ContactForm def index(request): cards = Cards.objects.all() return render(request,'card.html', {'cards':cards}) def contact(request): form = ContactForm() return render(request,'card.html', {'form': form}) This is my base.html #base.html {% load staticfiles %} >>> href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> >>> src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"> >>> src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"> >>> type="text/css"> Title OUR TEAM {% block content %} {% endblock %} And here is the card.html that is extended from base.html #card.html {% extends 'base.html' %} {% block content %} {% for card in cards %} >>> ontouchstart="this.classList.toggle('hover');"> >>> src="https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; alt="card image"> {{ card.name }} {{ card.description }} {{ card.name }} {% csrf_token %} {{ form }} {% endfor %} {% endblock %} As you may notice, I've called form by {{ form }} inside tag in card.html but the issue is that it just shows a Submit botton and ignores {{ form }}. Any idea how to
Re: How to fix: Django forms: {{ form }} is not working in a dynamic html page
I couldn't find a description field in the creation of your ContactForm. Maybe it's an oversight from me. However, if it isn't, I'm not expecting to see a {{card.description}} in your cards.html page. On 12:30PM, Fri, Jun 7, 2019 Delcy John wrote: > i think the error is in form.py,you must put indentation in class > > On Fri, Jun 7, 2019 at 9:37 AM Joe Reitman wrote: > >> Interesting problem. It won't display because the form is inside a >> for-loop. Django Template language looks at variables inside a for-loop >> differently. Basically it looks for a collection. Since {{ form }} is not a >> collection, it just ignores it. >> >> I'm not sure how you can create multiple forms like that. But I would be >> interested in knowing. >> >> >> On Thursday, June 6, 2019 at 6:14:57 PM UTC-5, Majid Rafiee wrote: >>> >>> I've created a form in Django: >>> >>> #forms.py >>> from django import forms >>> >>> >>> class ContactForm(forms.Form): >>> name = forms.CharField() >>> number = forms.FloatField() >>> eail_user = forms.EmailField() >>> >>> >>> and imported in in views.py >>> >>> #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom >>> cards.forms import ContactForm >>> >>> def index(request): >>> cards = Cards.objects.all() >>> return render(request,'card.html', {'cards':cards}) >>> >>> def contact(request): >>> form = ContactForm() >>> return render(request,'card.html', {'form': form}) >>> >>> This is my base.html >>> >>> #base.html >>> {% load staticfiles %} >>> >>> >>> >>> >> href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >>> rel="stylesheet" id="bootstrap-css"> >>> >> src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"> >>> >> src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"> >>> >> type="text/css"> >>> >>> >>> Title >>> >>> >>> >>> >>> OUR TEAM >>> >>> {% block content %} >>> {% endblock %} >>> >>> >>> >>> >>> >>> >>> >>> And here is the card.html that is extended from base.html >>> >>> #card.html >>> {% extends 'base.html' %} >>> >>> {% block content %} >>> >>> {% for card in cards %} >>> >>> >>> >> ontouchstart="this.classList.toggle('hover');"> >>> >>> >>> >>> >>> >> >>> src="https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; >>> alt="card image"> >>> {{ card.name }} >>> {{ card.description >>> }} >>> >>> >>> >>> >>> >>> >>> >>> {{ card.name }} >>> >>> >>> {% csrf_token %} >>> {{ form }} >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> {% endfor %} >>> >>> {% endblock %} >>> >>> >>> As you may notice, I've called form by {{ form }} inside tag in >>> card.html but the issue is that it just shows a Submit botton and ignores >>> {{ form }}. Any idea how to solve the issue? >>> I also bring urls.py in cards app and main urls: >>> #urls.py in cards >>> from django.urls import path >>> from . import views >>> >>> >>> urlpatterns = [ >>> path('', views.index), >>> path('form/', views.contact), >>> ] >>> >>> >>> #urls.py in main directory >>> >>> from django.contrib
Re: How to fix: Django forms: {{ form }} is not working in a dynamic html page
i think the error is in form.py,you must put indentation in class On Fri, Jun 7, 2019 at 9:37 AM Joe Reitman wrote: > Interesting problem. It won't display because the form is inside a > for-loop. Django Template language looks at variables inside a for-loop > differently. Basically it looks for a collection. Since {{ form }} is not a > collection, it just ignores it. > > I'm not sure how you can create multiple forms like that. But I would be > interested in knowing. > > > On Thursday, June 6, 2019 at 6:14:57 PM UTC-5, Majid Rafiee wrote: >> >> I've created a form in Django: >> >> #forms.py >> from django import forms >> >> >> class ContactForm(forms.Form): >> name = forms.CharField() >> number = forms.FloatField() >> eail_user = forms.EmailField() >> >> >> and imported in in views.py >> >> #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom >> cards.forms import ContactForm >> >> def index(request): >> cards = Cards.objects.all() >> return render(request,'card.html', {'cards':cards}) >> >> def contact(request): >> form = ContactForm() >> return render(request,'card.html', {'form': form}) >> >> This is my base.html >> >> #base.html >> {% load staticfiles %} >> >> >> >> > href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >> rel="stylesheet" id="bootstrap-css"> >> > src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"> >> > src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"> >> > type="text/css"> >> >> >> Title >> >> >> >> >> OUR TEAM >> >> {% block content %} >> {% endblock %} >> >> >> >> >> >> >> >> And here is the card.html that is extended from base.html >> >> #card.html >> {% extends 'base.html' %} >> >> {% block content %} >> >> {% for card in cards %} >> >> >> > ontouchstart="this.classList.toggle('hover');"> >> >> >> >> >> > >> src="https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; >> alt="card image"> >> {{ card.name }} >> {{ card.description >> }} >> >> >> >> >> >> >> >> {{ card.name }} >> >> >> {% csrf_token %} >> {{ form }} >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> {% endfor %} >> >> {% endblock %} >> >> >> As you may notice, I've called form by {{ form }} inside tag in >> card.html but the issue is that it just shows a Submit botton and ignores >> {{ form }}. Any idea how to solve the issue? >> I also bring urls.py in cards app and main urls: >> #urls.py in cards >> from django.urls import path >> from . import views >> >> >> urlpatterns = [ >> path('', views.index), >> path('form/', views.contact), >> ] >> >> >> #urls.py in main directory >> >> from django.contrib import admin >> from django.urls import path, include >> >> >> urlpatterns = [ >> path('admin/', admin.site.urls), >> path('calculator_one_input/', include('calculator_one_input.urls')), >> path('cards/', include('cards.urls')), >> path('cards/form/', include('cards.urls')), >> ] >> >> >> I looked for a solution for three days and still I have no idea how to >> solve this issue. I will be so appreciated if som
Re: How to fix: Django forms: {{ form }} is not working in a dynamic html page
Update. You can do this by hard coding the HTML form in the template. If you want to gather the data a user enters, each form will have to be uniquely identifiable and your view will have to determine which form its getting post data from. You can put the card index number in the button value and code your view to handle it based on the button value. On Thursday, June 6, 2019 at 11:07:18 PM UTC-5, Joe Reitman wrote: > > Interesting problem. It won't display because the form is inside a > for-loop. Django Template language looks at variables inside a for-loop > differently. Basically it looks for a collection. Since {{ form }} is not a > collection, it just ignores it. > > I'm not sure how you can create multiple forms like that. But I would be > interested in knowing. > > > On Thursday, June 6, 2019 at 6:14:57 PM UTC-5, Majid Rafiee wrote: >> >> I've created a form in Django: >> >> #forms.py >> from django import forms >> >> >> class ContactForm(forms.Form): >> name = forms.CharField() >> number = forms.FloatField() >> eail_user = forms.EmailField() >> >> >> and imported in in views.py >> >> #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom >> cards.forms import ContactForm >> >> def index(request): >> cards = Cards.objects.all() >> return render(request,'card.html', {'cards':cards}) >> >> def contact(request): >> form = ContactForm() >> return render(request,'card.html', {'form': form}) >> >> This is my base.html >> >> #base.html >> {% load staticfiles %} >> >> >> >> > href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >> rel="stylesheet" id="bootstrap-css"> >> > src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"> >> > src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"> >> > type="text/css"> >> >> >> Title >> >> >> >> >> OUR TEAM >> >> {% block content %} >> {% endblock %} >> >> >> >> >> >> >> >> And here is the card.html that is extended from base.html >> >> #card.html >> {% extends 'base.html' %} >> >> {% block content %} >> >> {% for card in cards %} >> >> >> > ontouchstart="this.classList.toggle('hover');"> >> >> >> >> >> > >> src="https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; >> alt="card image"> >> {{ card.name }} >> {{ card.description >> }} >> >> >> >> >> >> >> >> {{ card.name }} >> >> >> {% csrf_token %} >> {{ form }} >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> {% endfor %} >> >> {% endblock %} >> >> >> As you may notice, I've called form by {{ form }} inside tag in >> card.html but the issue is that it just shows a Submit botton and ignores >> {{ form }}. Any idea how to solve the issue? >> I also bring urls.py in cards app and main urls: >> #urls.py in cards >> from django.urls import path >> from . import views >> >> >> urlpatterns = [ >> path('', views.index), >> path('form/', views.contact), >> ] >> >> >> #urls.py in main directory >> >> from django.contrib import admin >> from django.urls import path, include >> >> >> urlpatterns = [ >> path('admin
Re: How to fix: Django forms: {{ form }} is not working in a dynamic html page
Interesting problem. It won't display because the form is inside a for-loop. Django Template language looks at variables inside a for-loop differently. Basically it looks for a collection. Since {{ form }} is not a collection, it just ignores it. I'm not sure how you can create multiple forms like that. But I would be interested in knowing. On Thursday, June 6, 2019 at 6:14:57 PM UTC-5, Majid Rafiee wrote: > > I've created a form in Django: > > #forms.py > from django import forms > > > class ContactForm(forms.Form): > name = forms.CharField() > number = forms.FloatField() > eail_user = forms.EmailField() > > > and imported in in views.py > > #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom > cards.forms import ContactForm > > def index(request): > cards = Cards.objects.all() > return render(request,'card.html', {'cards':cards}) > > def contact(request): > form = ContactForm() > return render(request,'card.html', {'form': form}) > > This is my base.html > > #base.html > {% load staticfiles %} > > > > href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" > rel="stylesheet" id="bootstrap-css"> > src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"> > src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"> > type="text/css"> > > > Title > > > > > OUR TEAM > > {% block content %} > {% endblock %} > > > > > > > > And here is the card.html that is extended from base.html > > #card.html > {% extends 'base.html' %} > > {% block content %} > > {% for card in cards %} > > > ontouchstart="this.classList.toggle('hover');"> > > > > > > src="https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; > alt="card image"> > {{ card.name }} > {{ card.description > }} > class="fa fa-plus"> > > > > > > > {{ card.name }} > > > {% csrf_token %} > {{ form }} > > > > > > target="_blank" href="#"> > > > > > target="_blank" href="#"> > > > > > target="_blank" href="#"> > > > > > target="_blank" href="#"> > > > > > > > > > > > > {% endfor %} > > {% endblock %} > > > As you may notice, I've called form by {{ form }} inside tag in > card.html but the issue is that it just shows a Submit botton and ignores > {{ form }}. Any idea how to solve the issue? > I also bring urls.py in cards app and main urls: > #urls.py in cards > from django.urls import path > from . import views > > > urlpatterns = [ > path('', views.index), > path('form/', views.contact), > ] > > > #urls.py in main directory > > from django.contrib import admin > from django.urls import path, include > > > urlpatterns = [ > path('admin/', admin.site.urls), > path('calculator_one_input/', include('calculator_one_input.urls')), > path('cards/', include('cards.urls')), > path('cards/form/', include('cards.urls')), > ] > > > I looked for a solution for three days and still I have no idea how to > solve this issue. I will be so appreciated if someone give me a clear clue > how to solve. Thanks > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsu
How to fix: Django forms: {{ form }} is not working in a dynamic html page
I've created a form in Django: #forms.py from django import forms class ContactForm(forms.Form): name = forms.CharField() number = forms.FloatField() eail_user = forms.EmailField() and imported in in views.py #views.pyfrom django.shortcuts import renderfrom .models import Cardsfrom cards.forms import ContactForm def index(request): cards = Cards.objects.all() return render(request,'card.html', {'cards':cards}) def contact(request): form = ContactForm() return render(request,'card.html', {'form': form}) This is my base.html #base.html {% load staticfiles %} Title OUR TEAM {% block content %} {% endblock %} And here is the card.html that is extended from base.html #card.html {% extends 'base.html' %} {% block content %} {% for card in cards %} https://sunlimetech.com/portfolio/boot4menu/assets/imgs/team/img_01.png"; alt="card image"> {{ card.name }} {{ card.description }} {{ card.name }} {% csrf_token %} {{ form }} {% endfor %} {% endblock %} As you may notice, I've called form by {{ form }} inside tag in card.html but the issue is that it just shows a Submit botton and ignores {{ form }}. Any idea how to solve the issue? I also bring urls.py in cards app and main urls: #urls.py in cards from django.urls import path from . import views urlpatterns = [ path('', views.index), path('form/', views.contact), ] #urls.py in main directory from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('calculator_one_input/', include('calculator_one_input.urls')), path('cards/', include('cards.urls')), path('cards/form/', include('cards.urls')), ] I looked for a solution for three days and still I have no idea how to solve this issue. I will be so appreciated if someone give me a clear clue how to solve. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/014f5076-7281-4183-9c96-54900bf796c3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.