How to provide function calling event for button in django html templates ?

97 views
Skip to first unread message

Mayur Bagul

unread,
Apr 20, 2019, 3:17:02 AM4/20/19
to Django users
Hello Community,

i'm facing one problem. Scenario is such that i have one template login.html in Django Project, inside this file i have wrote html code for login purpose.

what i want that once user click on Log-In Button it should call function ( onclick using Javascript cant use in Django) which will check password and username.
if username and password is Correct then it will go to next page which is main page else it will return prompt or alert 'Wrong Credentials".

but im not getting how i can do this in Django ?

So guys Please help me out of this issue.

Thanking you,
Mayur Bagul.

Gil Obradors

unread,
Apr 20, 2019, 3:22:32 AM4/20/19
to django...@googlegroups.com
Hi!

If you want you can re-use django.contrib.auth package

Otherwise, you can do a POST to a URL, and this url (url.py) call a function ( views.py)

Good luck!




Missatge de Mayur Bagul <mayur....@gmail.com> del dia ds., 20 d’abr. 2019 a les 9:17:
--
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...@googlegroups.com.
To post to this group, send email to django...@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/0fd23be8-b2d7-437e-b3e7-05c1f5bcdf4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mayur Bagul

unread,
Apr 20, 2019, 3:31:15 AM4/20/19
to Django users
hello gil,

thanks for tutorial link i will check it out that one. 
As you gave solution of calling a function via view i did so but it didnt worked and another thing i dint understand is about post i thought it didnt support in django.

can you please provide me little code your talking about post method?  it will be helpful.

thanking you.


On Saturday, April 20, 2019 at 12:52:32 PM UTC+5:30, Gil Obradors wrote:
Hi!

If you want you can re-use django.contrib.auth package

Otherwise, you can do a POST to a URL, and this url (url.py) call a function ( views.py)

Good luck!




Missatge de Mayur Bagul <mayur...@gmail.com> del dia ds., 20 d’abr. 2019 a les 9:17:
Hello Community,

i'm facing one problem. Scenario is such that i have one template login.html in Django Project, inside this file i have wrote html code for login purpose.

what i want that once user click on Log-In Button it should call function ( onclick using Javascript cant use in Django) which will check password and username.
if username and password is Correct then it will go to next page which is main page else it will return prompt or alert 'Wrong Credentials".

but im not getting how i can do this in Django ?

So guys Please help me out of this issue.

Thanking you,
Mayur Bagul.

--
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...@googlegroups.com.

Gil Obradors

unread,
Apr 20, 2019, 3:40:05 AM4/20/19
to django...@googlegroups.com
Before continuing with this, read some about http methods like : https://www.tutorialspoint.com/http/http_methods.htm

Yes, it's suported.

one example function playing with post requests:

def form(request):
	form = facturaForm
	if request.method == 'POST':
		print(request.POST)
	return render(request, 'demanoaltaform.html', {'form' : form})

Missatge de Mayur Bagul <mayur....@gmail.com> del dia ds., 20 d’abr. 2019 a les 9:31:
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Jani Tiainen

unread,
Apr 20, 2019, 7:35:26 AM4/20/19
to django...@googlegroups.com
Hi,

I also suggest that take a look at Django Girls tutorial. It does pretty good job at describing web basics and django same time.




--
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...@googlegroups.com.
To post to this group, send email to django...@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/0fd23be8-b2d7-437e-b3e7-05c1f5bcdf4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Jani Tiainen
Software wizard


Always open for short term jobs or contracts to work with Django.
Reply all
Reply to author
Forward
0 new messages