django-forms

Validation error not showing on form

我是研究僧i 提交于 2020-02-07 10:17:32
问题 I'm creating a SignUp form and it displays the validation errors, such as required fields. However, using Django-Crispy-Forms, the validation errors do not appear. I'm customizing the default form from Django-allauth, which raises ValidationError. However, using Django-Crispy forms, no errors get displayed on the form. 1.template {% extends "base.html" %} {% load i18n %} {% load crispy_forms_tags %} {% block content %} <div class="big-box"> <p><h1>{% trans "Sign Up" %}</h1></p> <p>{%

request.GET vs request.POST/Redirect/GET in django

 ̄綄美尐妖づ 提交于 2020-02-05 08:16:20
问题 In dealing with forms with multiple input parameters and pagination, where user can choose any number of parameters (like a search form) which approach is better and why? receiving data straight from request.GET in one view or implementing a Post/Redirect/Get (2 views). using Post/Redirect/Get, one can easily sanitize data using ModelForms builtin methods: if request.method == 'POST': form = MySearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data #do stuff with cd How would you

Unable to upload image to Django Project, getting Form object has no attribute 'save'

怎甘沉沦 提交于 2020-02-04 03:53:18
问题 I am trying to upload an image file through a file input from a template. I have followed all the instructions but getting this error when attaching the file and clicking on submit. AttributeError: 'PicUpForm' object has no attribute 'save' and hence my image is not uploading to the specified directory as well as the record is not inserting into my sqlitedb FOLLOWING ARE ALL THE NECESSARY CODES I HAVE USED: views.py def add_image(request): form = PicUpForm() if request.method == "POST": form

access parent form's cleaned_data from inline form clean()

依然范特西╮ 提交于 2020-02-02 02:59:08
问题 I have a main form that has an inline-form. Is it possible to access the main form's cleaned_data from the inline-form's clean function? Here is why I am asking. The main form has a field to define if a property is for-sale or to lease. The inline form then displays either a sale price field or fields for the lease amount and deposit. I am trying to validate that if the property is for sale, then the lease and deposit fields should be empty. I can do this in a view for the frontend interface,

Editing related models in profile form using django-profiles

若如初见. 提交于 2020-02-01 07:45:27
问题 I'm using django-profiles in my app, as it gives me a few simple views that helps me get where I want to go, faster. However, I have one problem. Given the models below, how can I create a form for editing a profile that includes all the fields on UserProfile , the first_name, last_name and email fields from User , and one or more PhoneNumber s? from django.db import models from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ class UserProfile

Dropdown in Django Model

依然范特西╮ 提交于 2020-01-30 14:23:12
问题 I want to create a field in Django models.py which will render as a dropdown and user can select the options from there. If I have 5 choices: GREEN BLUE RED ORANGE BLACK How should I write my code in models.py and Forms.py so that the template renders it like a dropdown element? 回答1: Specify CharField or IntegerField with choices option in your model https://docs.djangoproject.com/en/1.8/ref/models/fields/#choices and use ModelForm https://docs.djangoproject.com/en/1.8/topics/forms/modelforms

Dropdown in Django Model

99封情书 提交于 2020-01-30 14:22:04
问题 I want to create a field in Django models.py which will render as a dropdown and user can select the options from there. If I have 5 choices: GREEN BLUE RED ORANGE BLACK How should I write my code in models.py and Forms.py so that the template renders it like a dropdown element? 回答1: Specify CharField or IntegerField with choices option in your model https://docs.djangoproject.com/en/1.8/ref/models/fields/#choices and use ModelForm https://docs.djangoproject.com/en/1.8/topics/forms/modelforms

ValueError: not enough values to unpack (expected 2, got 1)

↘锁芯ラ 提交于 2020-01-25 21:31:27
问题 the following is my code views.py from django.shortcuts import render from .forms import MedicineForm from .models import Medicine def index(request): all_medicine = Medicine.objects.order_by('id') return render(request, 'medicine/index.html', {'all_medicine': all_medicine}) def add(request): if request.method == 'POST': form = MedicineForm(request.POST) if form.is_valid(): new = Medicine() new.name = form.cleaned_data['药品名称'] new.price = form.cleaned_data['药品价格'] new.number = form.cleaned

Pass multiple checkbox selections in a template to a form

吃可爱长大的小学妹 提交于 2020-01-25 10:06:55
问题 I'm new to Django and i'm still learning the ropes. I have the following template, that allows the user to select multiple check boxes. Now I'd like for those options to be passed to a new url path after the user pushes a button. If i'm going about this the wrong way let me know and give a suggestion. <div class="container"> <div class="row"> <div class="col"> <h3>Financial</h3> <ul> {% for app in fingrouplist %} <li><input type="checkbox" name="request_reports" value ="{{app.report_id}}" > {

Pass multiple checkbox selections in a template to a form

别等时光非礼了梦想. 提交于 2020-01-25 10:05:05
问题 I'm new to Django and i'm still learning the ropes. I have the following template, that allows the user to select multiple check boxes. Now I'd like for those options to be passed to a new url path after the user pushes a button. If i'm going about this the wrong way let me know and give a suggestion. <div class="container"> <div class="row"> <div class="col"> <h3>Financial</h3> <ul> {% for app in fingrouplist %} <li><input type="checkbox" name="request_reports" value ="{{app.report_id}}" > {