Getting |as_crispy_field got passed an invalid or inexistent field - django

Im using crispy field on inputs for css speed.
I have my {{from.username|as_crispy_field}}.
When i submit the data i get a CrispyError at /client error.
Exception Type: CrispyError
Exception Value:
|as_crispy_field got passed an invalid or inexistent field
What do i need to do to handle this in views ?

it is supposed to be {{form.username|as_crispy_field}} instead of {{from.username|as_crispy_field}}.
PS. This is about 3 years old but I hope the answer will help someone at some point. Cheers!

Related

MultiValueDictKeyError at /add

Each time I add Project with Expense Category. It's displaying error in the browser
MultiValueDictKeyError at /add 'categoriesString'
Although the Project is getting saved in the database!
Please help me to figure it out!
in the form's html field put name="categoriesString" for the input field where you are passing data

django formset not working properly after removing few forms

I'm using a django formset having 5 forms. After entering data and posting them to my. I validate the formset and save the valid forms(suppose 2 are saved) and remove them from formset and unvalidated forms(3 in this case) are rendered back on django template. Now, after correcting the data on these 3 forms, I post them again.
Now in my view, I'm getting 5 forms again
and 2 forms which were saved earlier are posted with empty data.. because of which my
formset.is_valid()
returns false and error is raised.
Can anybody tell me the reason why this is happening and how to fix it?
Thanks in advance!
EDIT: I have found out that issue is because form-TOTAL_FORMS and form-INITIAL_FORMS are still not same ater removing forms. Any quick help to update these numbers?

django url template tag - module not found error

Django seems to be categorically rejecting ALL of my url template tags.
Whenever I run a page, in this case /accounts/login/, I get the following error:
Caught ViewDoesNotExist while rendering: Tried user_profile in module cozcus.views. Error was: 'module' object has no attribute 'form'
The django error pages then proceed to point out the url tags as where things went wrong.
Here's what I know: it's not a problem with the syntax of the url tags, as that would normally return:
Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
arguments '{}' not found."
There was another question about this error on this website, which can be found here, but what went wrong was that there was a URL setting that pointed to a page that didn't exist. I checked all of my urls, and they all point to existing views.
Does anyone have anything else i could try? Your help is much appreciated.
I Think you are importing a form somewhere where you have inherited
forms.form
instead of
forms.Form
(Capital F).

Django: Passing model object values through url

I'm having problems with passing model object values through a URL pattern. The URL:
url(r'^cities/(?P<city>\w+)/$', 'city_firm', name='city_firm'),
In the template (from the index page) I have:
{{ city }}
This is in a for loop.
The related view is:
def city_firm(request, city):
city1 = Cities.objects.get(city=city)
cityf = city1.Firms.all()
return render_to_response('cityfirm.html', {'cityf': cityf})
The two models (Cities, Firms) are in a many to many relationship.
I keep getting TemplateSyntaxError at index (NoReverseMatch while rendering: Reverse for 'city_firm' with arguments '(<Cities: >,)' and keyword arguments '{}' not found). In the template link tag I tried: {% url city_firm city=city %}, {% url city_firm city=cities.city %}. Nothing changed. The urlconf part seems right. The problem seems to be in the template. Maybe there is an issue with the string values of the object as they aren't in English. But I took several precautions to prevent this. There is maybe something wrong with the view but the error says template. Any ideas?
Solution:
Thanks everyone! Finally I figured it out. The problem was simple: I was trying to send object attribute names through the url, that had non-English characters and spaces. To fix it, I had to edit my models.
The issue is that you can't pass an object in a URL, you can only pass characters. So you need to put the part of the city object that contains the text you want to be in the URL - in your case, it appears to be an attribute also called city, which is what you use to in the lookup to get the object in the view. So it should be:
{{ city }}
I don't think name means what you think it does - remove that and read this: http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns
As far as the error... the NoReverseMatch is telling you that it's not seeing any arguments. Remember that nonexisting template variables expand to "". Make sure city is in context when you're running that code - maybe post the for in the template?

How to make required field error message don't show up for first time in Django

First time I render a form I don't want the required error message to show up. Although if the field is left empty, it should prompt when submitting.
I know I can set an specific message and set it empty. But this way it never shows up:
error_messages = {'required':''}
I'm using a decorator to change label_tag behavior in BoundField, that makes an "*" show up next to the field label. But I need the error message to show up, only if field is empty.
I know I can check if field is required using:
{% if field.field.required %}
But I would need a way to know if the site is being rendered for the first time. For this I would like not to use an extra variable passed from the view or javascript. I have noticed that formsets actually work this way, but I don't want to put the form in a formset of one form
Error messages don't show up the first time anyway, if you're following the correct pattern in your view.
I suspect the error is showing because you're instantiating the form with a data parameter. You shouldn't do this when you're displaying it on the first GET. The proper way to do it is shown in the documentation.