Re: Binding hand written HTML(form) or forms that are not created through djnago forms to django forms validation errors

2015-03-10 Thread Scot Hacker


On Tuesday, March 10, 2015 at 4:10:48 AM UTC-7, Mahesh Thipparthi wrote:
>
> Hi All,
> Kindly help me with following questions.
>  
> Use case is this:
> 1. i have created a form manually ( not generated through django forms)
> 2. I am calling a Django view function upon submission.
> 3. validating the field through django form as i ensured that form names 
> are same.
>

>From your example code, I'm guessing the reason why you don't want to use a 
Django form is because you need to have  Bootstrap classes  on the form 
elements. A much better way to skin this cat is to use a standard Django 
form and then render it out with 
django-bootstrap-forms: https://django-bootstrap-form.readthedocs.org/en/latest/

./s

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58f66a37-a512-44c6-ac22-1e5958a70a6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Binding hand written HTML(form) or forms that are not created through djnago forms to django forms validation errors

2015-03-10 Thread Vijay Khemlani
Unbound forms have no validation errors as they haven't been filled yet by
the user.

I think you are trying to solve the wrong problem. Why are you creating
your form manually in the first place? Your HTML markup is easy to do with
Django forms and packages suck as crispy forms

On Tue, Mar 10, 2015 at 4:02 AM, Mahesh Thipparthi <
mahesh.thippar...@gmail.com> wrote:

> Hi All,
> Kindly help me with following questions.
>
> Use case is this:
> 1. i have created a form manually ( not generated through django forms)
> 2. I am calling a Django view function upon submission.
> 3. validating the field through django form as i ensured that form names
> are same.
>
> question is
> 1. How to pass on validation errors from Djnago form to non django forms?
> Please suggest better ways to do this.
>
> Note. I see one way is to jsonify the errors and reconstruct the DOM
>
>
> Let me take an example.
> I do not want to use Djnago generated form hence i have written my own
> login page:
>
> **
>
> *Login to Application*
>
> * "auth_login" %}  > {% csrf_token %}*
>
> **
>
> **
>
> *   name="username" >User ID  *
>
> *   ="username" placeholder="User name">*
>
> **
>
> * *
>
> *  Password *
>
> *   id="password" placeholder="Password">*
>
> *  *
>
> **
>
>   **
>
> *Sign
> in*
>
> **
>
> **
>
>   **
>
> * *
>
> action is passed to view where i am trying to do this.
>
>   def login_view(request):
>
> if request.POST:
>
> form = LoginForm(request.POST or None)
>
> if form.is_valid():
>
> username = form.cleaned_data['username']
>
> password = form.cleaned_data['password']
>
> user = authenticate(username=username, password=password)
>
> login(request, user)
>
> return HttpResponseRedirect(reverse("menu"))
>
> else:
>
> form = LoginForm()
>
>   context = {"form": form,}
> return render(request, "login.html", context)
>
> *when ther are form eeors invalid user id or pasword..waht is the way
> to pass valiadtion errors to "UNBOUND Form".*
> *I personally see only way to return jason response and process it on
> unbound form?is there anyway djnago can directly pass validation errors
> to forms that are not created by djnago?*
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6f74d6f9-1c29-4ce7-b2df-4f74b8fefb05%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2QUOPFLwqn8z2kLv261wNB5cfLPEAVm%3DbO2dYWGrrnJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Binding hand written HTML(form) or forms that are not created through djnago forms to django forms validation errors

2015-03-10 Thread Mahesh Thipparthi
Hi All,
Kindly help me with following questions.
 
Use case is this:
1. i have created a form manually ( not generated through django forms)
2. I am calling a Django view function upon submission.
3. validating the field through django form as i ensured that form names 
are same.

question is
1. How to pass on validation errors from Djnago form to non django forms?
Please suggest better ways to do this.

Note. I see one way is to jsonify the errors and reconstruct the DOM


Let me take an example.
I do not want to use Djnago generated form hence i have written my own 
login page:

**

*Login to Application*

* {% csrf_token %}*

**

**

*  User ID  *

*  *

**

* *

*  Password *

*  *

*  *

**

  **

*Sign 
in*

**

**

  **

* *
  
action is passed to view where i am trying to do this.

  def login_view(request):

if request.POST:

form = LoginForm(request.POST or None)

if form.is_valid():

username = form.cleaned_data['username']

password = form.cleaned_data['password']

user = authenticate(username=username, password=password)

login(request, user)

return HttpResponseRedirect(reverse("menu"))

else:

form = LoginForm()

  context = {"form": form,}
return render(request, "login.html", context)  

*when ther are form eeors invalid user id or pasword..waht is the way 
to pass valiadtion errors to "UNBOUND Form".*
*I personally see only way to return jason response and process it on 
unbound form?is there anyway djnago can directly pass validation errors 
to forms that are not created by djnago?*


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f74d6f9-1c29-4ce7-b2df-4f74b8fefb05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.