Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
I'm using python code to verify the fields. I'm doing it on a View. But with javascript maybe I can solve this issue where i don't need to reload the page. But if i do that, can i do things like check the database to see if it already contains some value? Or store something on request.session for later? On Thursday, November 2, 2017 at 6:43:18 PM UTC-3, James Schneider wrote: > > > > On Thu, Nov 2, 2017 at 12:57 PM, fábio andrews rocha marques < > fabioandrews...@gmail.com > wrote: > >> To use django forms is to use the django Form class and it's components >> on a view? How will this solve the issue? If i use the components, don't i >> have to re-render the page when a user makes an error on the form? >> >> > Are you submitting and rendering the information entirely via JavaScript? > That would be the only case where you may get errant messages on the same > page where the user submitted the form. You'll need to examine your JS > workflow, as that is not a Django issue. > > You'll integrate the form usage within your view. The Django tutorial > covers this using both function-based views and class-based views. You > should do this even when submitting the information via AJAX/JS, but the > page doesn't necessarily need to be redirected because your JS will handle > re-rendering the page properly. I'd recommend the Django Rest Framework > package in that case. > > -James > -- 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/f089a104-ed0e-4ae0-9567-668e4422fb57%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
To use django forms is to use the django Form class and it's components on a view? How will this solve the issue? If i use the components, don't i have to re-render the page when a user makes an error on the form? On Tuesday, October 31, 2017 at 7:50:38 PM UTC-3, James Schneider wrote: > > > > On Oct 30, 2017 4:46 PM, "fábio andrews rocha marques" < > fabioandrews...@gmail.com > wrote: > > Let's say i have a "register a new user" View and on this page, when the > user forgets to inform a password or a username, i show a message to him on > the same page saying "you forgot the password". The way i do this is by > doing this(on my View.py in a function called cadastrarprofessor): > > nomeusuario = request.POST['usuario'] #username > nomesenha = request.POST['senha'] #password > nomeemail = request.POST['email'] #email > > if not nomeusuario: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um usuário", > 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) > elif not nomesenha: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, > 'nomeusuariocadastro':nomeusuario}) > elif not nomeemail: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, > 'nomeusuariocadastro':nomeusuario}) > > And my template for this page(cadastro.html) is like this: > > Cadastro > > {% csrf_token %} > Usuário: > {% if nomeusuariocadastro %} > nomeusuariocadastro }}> > {% else %} > > {% endif %} > > > ... (DO THE SAME TO SENHA/PASSWORD AND EMAIL) > > > > > > {% csrf_token %} > > {% if cadastrorealizadocomsucesso is True %}cadastro realizado com > sucesso!{% endif %} > {% if error_message %}{{ error_message }}{% endif > %} > > So, every time the user forgets to mention a username or email or password > in this screen, i use render to redirect the user to the same page but this > time displaying a error_message. Let's say he did forget to fill the > textfield with a username... he goes back to the same page and sees the > error message. After that, let's say everything is right and he finally > registers a new user, he sees "cadastro realizado com sucesso"(sucessfully > registered new user) and stays on the same page. But when he goes back a > page(pressing "back" on the browser), instead of going back to the page > before the cadastro.html, he goes back to the same page cadastro.html but > displaying the error message for the "you forgot to mention your username". > I don't want him to go back to the same page with error message, i want to > make him go back to my main menu. > > > There is very little that you can do to prevent this type of behavior when > the user presses the back button. > > After the user successfully authenticates, they should be redirected to > the proper landing page by using an HTTP 302 redirect. This is very common > and baked in to all of the generic form handling views provided by Django. > If the page is redirected, then the user will encounter a warning pop up > from the browser asking if they want to resubmit the data. Generally this > is enough to scare users away from using the back button, but even if they > do continue through the warning, they'll simply reauthenticate and be > redirected to the same landing page, again. > > If that is not happening, them your form processing workflow is incorrect. > > From your view, you aren't using Django forms at all. I would highly > encourage you to do so, especially to better understand how form data > should be processed and validated, and how to properly handle responses > back to the client. The Django tutorial covers this topic. > > -James > -- 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/9875e51c-ede8-4a9b-890a-75da0e8c0183%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
How did you use the never_cache? Because if i just put @never_cache before the def of my view: def cadastrarprofessor(request):, it's like it doesn't do anything (i am on the login page, I go to the registration page, inform a name of a user that already exists, click "register", the system refreshes the page telling me that the user already exists and when i press the "back button" from the browser, it goes back to the registration page with empty fields, which is not what iwant. I want to go back to the login page, the page before the registration). Do I have to use @never_cache and remove all the return render from my function? What should i return instead? On Tuesday, October 31, 2017 at 2:46:01 PM UTC-3, Matthew Pava wrote: > > I had a similar issue and even tried using sessions, but I eventually > found that never_cache worked beautifully for me. I didn’t have to worry > about sessions any more. > > > > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *fábio andrews > rocha marques > *Sent:* Tuesday, October 31, 2017 12:19 PM > *To:* Django users > *Subject:* Re: do i always have to reload/return render a page to show > the errors? if i press go back on browser, i see screens with the error > message > > > > I found this topic within stackoverflow: > https://stackoverflow.com/questions/10906548/django-redirect-behavior-with-back-button > > > > that seems to me that the user was having the same problem as i am. The > only answer i found could work was from magicTuscan, but he just said "I > would save the last site path as a session, then retrieve via the view when > the page is called again via the back button". I've tried to contact him > but didn't get an answer. Is it possible to override the "browser back > button" behavior on django using sessions? > > -- > 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 djang...@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/3ad05d02-cecd-4560-9654-82d2ed1106ca%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/3ad05d02-cecd-4560-9654-82d2ed1106ca%40googlegroups.com?utm_medium=email_source=footer> > . > 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa86e291-ad2e-4b5a-b78a-1e98327189ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
I found this topic within stackoverflow: https://stackoverflow.com/questions/10906548/django-redirect-behavior-with-back-button that seems to me that the user was having the same problem as i am. The only answer i found could work was from magicTuscan, but he just said "I would save the last site path as a session, then retrieve via the view when the page is called again via the back button". I've tried to contact him but didn't get an answer. Is it possible to override the "browser back button" behavior on django using sessions? -- 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/3ad05d02-cecd-4560-9654-82d2ed1106ca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
Yes, my code has an else condition that always returns a render. The error_message is populated according to the error made by the user, like "forgot your username","forgot password", "username already exists". Since i always need to return an httpresponse or render in my django view, will the page always refresh? Here's the full code of my view currently: def cadastrarprofessor(request): if 'terminarcadastroprofessor' in request.POST: # if this is a POST request we need to process the form data if request.method == 'POST': nomeusuario = request.POST['usuario'] nomesenha = request.POST['senha'] nomeemail = request.POST['email'] print("nomeusuario:") print(nomeusuario) if not nomeusuario: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) elif not nomesenha: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 'nomeusuariocadastro':nomeusuario}) elif not nomeemail: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario}) elif User.objects.filter(username=nomeusuario).exists(): return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "nome de usuário já existe", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario, 'nomeemailcadastro':nomeemail}) else: usuarionovo = User.objects.create_user(nomeusuario, nomeemail, nomesenha) novoprofessor = Professor(user=usuarionovo,nome=nomeusuario) novoprofessor.save() return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': True}) else: return render(request,'index.html') else: #vou para tela do inicio do cadastro. Era um link entao nao tem POST return render(request, 'cadastro.html',{'cadastrorealizadocomsucesso':False}) On Tuesday, October 31, 2017 at 1:47:31 PM UTC-3, Matthew Pava wrote: > > > to do this, i just have to put the @never_cache on my View's method, > right? > > > > Yes. > > > > Upon further investigation of your code, I suggest looking into Django > forms and utilizing them. Also, you shouldn’t need to use two forms on > your log-in view. The submit button should go inside the log-in form. > > > > To get back to fixing your current code, do you have an else condition > that always returns a render? And, yes, you need to return an HttpResponse > object in all of your view functions, which is returned by the render > function. It looks like you are always populating ‘error_message,’ which > is why there is always an error_message rendered. > > > > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *fábio andrews > rocha marques > *Sent:* Tuesday, October 31, 2017 11:06 AM > *To:* Django users > *Subject:* Re: do i always have to reload/return render a page to show > the errors? if i press go back on browser, i see screens with the error > message > > > > to do this, i just have to put the @never_cache on my View's method, > right? (after importing 'from django.views.decorators.cache import > never_cache'). For some reason, when i did this, the page started and i > already got the message "usuário já existe"(username already exists) and > still the problem i stated occurred. Is it something i am doing wrong? > Like, i should remover the return renders from my function after putting > @never_cache? > > On Tuesday, October 31, 2017 at 11:25:28 AM UTC-3, Matthew Pava wrote: > > Try using the @never_cache decorator on your login view. > > > https://docs.djangoproject.com/en/1.11/topics/http/decorators/#django.views.decorators.cache.never_cache > > > > > > *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On > Behalf Of *fábio andrews rocha marques > *Sent:* Tuesday, October 31, 2017 9:15 AM > *To:* Django users > *Subject:* Re: do i always have to reload/return render a page to show > the errors? if i press go back on browser, i see screens with the error > message > > > > That's a great suggestion. Sure, it will help on situations where i just > want the fields to be completed. But there are some fields that require a > little more feedback than that. Like, if a username already exists... I > check if it already exists using a View and checking on the database. So, > after the View checks if the user already exists, i have to render the page > again to show the error. > > On Tuesday, October 31, 2017 at 8:37:05 AM UTC-3, Eric Pascu
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
to do this, i just have to put the @never_cache on my View's method, right? (after importing 'from django.views.decorators.cache import never_cache'). For some reason, when i did this, the page started and i already got the message "usuário já existe"(username already exists) and still the problem i stated occurred. Is it something i am doing wrong? Like, i should remover the return renders from my function after putting @never_cache? On Tuesday, October 31, 2017 at 11:25:28 AM UTC-3, Matthew Pava wrote: > > Try using the @never_cache decorator on your login view. > > > https://docs.djangoproject.com/en/1.11/topics/http/decorators/#django.views.decorators.cache.never_cache > > > > > > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *fábio andrews > rocha marques > *Sent:* Tuesday, October 31, 2017 9:15 AM > *To:* Django users > *Subject:* Re: do i always have to reload/return render a page to show > the errors? if i press go back on browser, i see screens with the error > message > > > > That's a great suggestion. Sure, it will help on situations where i just > want the fields to be completed. But there are some fields that require a > little more feedback than that. Like, if a username already exists... I > check if it already exists using a View and checking on the database. So, > after the View checks if the user already exists, i have to render the page > again to show the error. > > On Tuesday, October 31, 2017 at 8:37:05 AM UTC-3, Eric Pascual wrote: > > Hello > Sorry or I misunderstood your problem but what about using the required > field attribute ? It will make such controls and messages be handled > directly on the client side. > Best regards. > > Eric PASCUAL > > Centre Scientifique et Technique du Bâtiment > 290 route des Lucioles > 06560 SOPHIA ANTIPOLIS > http://www.cstb.fr > > > > From: django...@googlegroups.com [django...@googlegroups.com] on behalf > of fábio andrews rocha marques [fabioandrews...@gmail.com] > Sent: Tuesday, October 31, 2017 00:46 > To: Django users > Subject: do i always have to reload/return render a page to show the > errors? if i press go back on browser, i see screens with the error message > > Let's say i have a "register a new user" View and on this page, when the > user forgets to inform a password or a username, i show a message to him on > the same page saying "you forgot the password". The way i do this is by > doing this(on my View.py in a function called cadastrarprofessor): > > nomeusuario = request.POST['usuario'] #username > nomesenha = request.POST['senha'] #password > nomeemail = request.POST['email'] #email > > if not nomeusuario: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um usuário", > 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) > elif not nomesenha: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, > 'nomeusuariocadastro':nomeusuario}) > elif not nomeemail: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, > > 'nomeusuariocadastro':nomeusuario}) > > And my template for this page(cadastro.html) is like this: > > Cadastro > > {% csrf_token %} > Usuário: > {% if nomeusuariocadastro %} > nomeusuariocadastro }}> > {% else %} > > {% endif %} > > > ... (DO THE SAME TO SENHA/PASSWORD AND EMAIL) > > > > > > {% csrf_token %} > > {% if cadastrorealizadocomsucesso is True %}cadastro realizado com > sucesso!{% endif %} > {% if error_message %}{{ error_message }}{% endif > %} > > So, every time the user forgets to mention a username or email or password > in this screen, i use render to redirect the user to the same page but this > time displaying a error_message. Let's say he did forget to fill the > textfield with a username... he goes back to the same page and sees the > error message. After that, let's say everything is right and he finally > registers a new user, he sees "cadastro realizado com sucesso"(sucessfully > registered new user) and stays on the same page. But when he goes back a > page(pressing "back" on the browser), instead of going back to the page > before the cadastro.html, he goes back to the same page cadastro.html but > displaying the error message for the "you
Re: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
That's a great suggestion. Sure, it will help on situations where i just want the fields to be completed. But there are some fields that require a little more feedback than that. Like, if a username already exists... I check if it already exists using a View and checking on the database. So, after the View checks if the user already exists, i have to render the page again to show the error. On Tuesday, October 31, 2017 at 8:37:05 AM UTC-3, Eric Pascual wrote: > > Hello > Sorry or I misunderstood your problem but what about using the required > field attribute ? It will make such controls and messages be handled > directly on the client side. > Best regards. > > Eric PASCUAL > > Centre Scientifique et Technique du Bâtiment > 290 route des Lucioles > 06560 SOPHIA ANTIPOLIS > http://www.cstb.fr > > > > From: django...@googlegroups.com [django...@googlegroups.com > ] on behalf of fábio andrews rocha marques [ > fabioandrews...@gmail.com ] > Sent: Tuesday, October 31, 2017 00:46 > To: Django users > Subject: do i always have to reload/return render a page to show the > errors? if i press go back on browser, i see screens with the error message > > Let's say i have a "register a new user" View and on this page, when the > user forgets to inform a password or a username, i show a message to him on > the same page saying "you forgot the password". The way i do this is by > doing this(on my View.py in a function called cadastrarprofessor): > > nomeusuario = request.POST['usuario'] #username > nomesenha = request.POST['senha'] #password > nomeemail = request.POST['email'] #email > > if not nomeusuario: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um usuário", > 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) > elif not nomesenha: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, > 'nomeusuariocadastro':nomeusuario}) > elif not nomeemail: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, > > 'nomeusuariocadastro':nomeusuario}) > > And my template for this page(cadastro.html) is like this: > > Cadastro > > {% csrf_token %} > Usuário: > {% if nomeusuariocadastro %} > nomeusuariocadastro }}> > {% else %} > > {% endif %} > > > ... (DO THE SAME TO SENHA/PASSWORD AND EMAIL) > > > > > > {% csrf_token %} > > {% if cadastrorealizadocomsucesso is True %}cadastro realizado com > sucesso!{% endif %} > {% if error_message %}{{ error_message }}{% endif > %} > > So, every time the user forgets to mention a username or email or password > in this screen, i use render to redirect the user to the same page but this > time displaying a error_message. Let's say he did forget to fill the > textfield with a username... he goes back to the same page and sees the > error message. After that, let's say everything is right and he finally > registers a new user, he sees "cadastro realizado com sucesso"(sucessfully > registered new user) and stays on the same page. But when he goes back a > page(pressing "back" on the browser), instead of going back to the page > before the cadastro.html, he goes back to the same page cadastro.html but > displaying the error message for the "you forgot to mention your username". > I don't want him to go back to the same page with error message, i want to > make him go back to my main menu. > Is there a better approach to display error messages on the same page > instead of using return render like this: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um usuário", > 'nomeemailcadastro':nomeemail,'nomesenhacadastro':nomesenha}) > ? > > > -- > 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 django-users+unsubscr...@googlegroups.com >. > To post to this group, send email to django...@googlegroups.com > <mailto: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/3f70cd29-9edc-4272-a27e-534ee7f1e1a2%40googlegroups.com
do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message
Let's say i have a "register a new user" View and on this page, when the user forgets to inform a password or a username, i show a message to him on the same page saying "you forgot the password". The way i do this is by doing this(on my View.py in a function called cadastrarprofessor): nomeusuario = request.POST['usuario'] #username nomesenha = request.POST['senha'] #password nomeemail = request.POST['email'] #email if not nomeusuario: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) elif not nomesenha: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 'nomeusuariocadastro':nomeusuario}) elif not nomeemail: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario}) And my template for this page(cadastro.html) is like this: Cadastro {% csrf_token %} Usuário: {% if nomeusuariocadastro %} {% else %} {% endif %} ... (DO THE SAME TO SENHA/PASSWORD AND EMAIL) {% csrf_token %} {% if cadastrorealizadocomsucesso is True %}cadastro realizado com sucesso!{% endif %} {% if error_message %}{{ error_message }}{% endif %} So, every time the user forgets to mention a username or email or password in this screen, i use render to redirect the user to the same page but this time displaying a error_message. Let's say he did forget to fill the textfield with a username... he goes back to the same page and sees the error message. After that, let's say everything is right and he finally registers a new user, he sees "cadastro realizado com sucesso"(sucessfully registered new user) and stays on the same page. But when he goes back a page(pressing "back" on the browser), instead of going back to the page before the cadastro.html, he goes back to the same page cadastro.html but displaying the error message for the "you forgot to mention your username". I don't want him to go back to the same page with error message, i want to make him go back to my main menu. Is there a better approach to display error messages on the same page instead of using return render like this: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) ? -- 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/3f70cd29-9edc-4272-a27e-534ee7f1e1a2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: make a button element outside be on the right side of another element inside
unfortunally, it does trigger. I have an input and a button. The button is "?" and the input is my submit form button On Thursday, September 28, 2017 at 9:19:01 PM UTC-3, Vijay Khemlani wrote: > > An input with type "button" instead of "submit" should not trigger the > form submit. > > On Thu, Sep 28, 2017 at 7:56 PM, fábio andrews rocha marques < > fabioandrews...@gmail.com > wrote: > >> In my template, I have a form. This form has a lot of textfields and a >> submit button. There's another button, lets name it "?", that displays a >> popup window whenever it's clicked. >> I want the "?" button to be on the right side of one of the textfields on >> my form. The problem is: since the form has an action associated with it, >> if i put the button inside the form, whenever the user clicks on it, the >> system computes it's action as if the submit button was clicked too... I >> don't want this to happen. >> >> How can i position my "?" button to the right of a component which is >> inside a even though my "?" button is outside the ? >> >> -- >> 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/96716dc0-19d9-46e0-9c04-f0e644c57b8c%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/96716dc0-19d9-46e0-9c04-f0e644c57b8c%40googlegroups.com?utm_medium=email_source=footer> >> . >> 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68b2dc94-8026-4bc9-b1f3-f636d76713b5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
make a button element outside be on the right side of another element inside
In my template, I have a form. This form has a lot of textfields and a submit button. There's another button, lets name it "?", that displays a popup window whenever it's clicked. I want the "?" button to be on the right side of one of the textfields on my form. The problem is: since the form has an action associated with it, if i put the button inside the form, whenever the user clicks on it, the system computes it's action as if the submit button was clicked too... I don't want this to happen. How can i position my "?" button to the right of a component which is inside a even though my "?" button is outside the ? -- 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/96716dc0-19d9-46e0-9c04-f0e644c57b8c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
override default "go back" action on a web page to go back to main menu
Let's say i have a "register a new user" View and on this page, when the user forgets to inform a password or a username, i show a message to him on the same page saying "you forgot the password". The way i do this is by doing this(on my View.py in a function called cadastrarprofessor): nomeusuario = request.POST['usuario'] #username nomesenha = request.POST['senha'] #password nomeemail = request.POST['email'] #email if not nomeusuario: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) elif not nomesenha: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 'nomeusuariocadastro':nomeusuario}) elif not nomeemail: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario}) And my template for this page(cadastro.html) is like this: Cadastro {% csrf_token %} Usuário: {% if nomeusuariocadastro %} {% else %} {% endif %} ... (DO THE SAME TO SENHA/PASSWORD AND EMAIL) {% csrf_token %} {% if cadastrorealizadocomsucesso is True %}cadastro realizado com sucesso!{% endif %} {% if error_message %}{{ error_message }}{% endif %} So, every time the user forgets to mention a username or email or password in this screen, i use render to redirect the user to the same page but this time displaying a error_message. Let's say he did forget to fill the textfield with a username... he goes back to the same page and sees the error message. After that, let's say everything is right and he finally registers a new user, he sees "cadastro realizado com sucesso"(sucessfully registered new user) and stays on the same page. But when he goes back a page, instead of going back to the page before the cadastro.html, he goes back to the same page cadastro.html but displaying the error message for the "you forgot to mention your username". I don't want him to go back to the same page with error message, i want to make him go back to my main menu. Is there any way to override the current page "go back" action? Is there a better approach to display error messages on the same page instead of using: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) ? -- 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/c6a0809a-21e4-4af8-b674-b8ae27f724c2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: utf-8' codec can't decode byte 0x93 in position 31 even though i use read().decode('utf-8') when i read a UploadedFile i get from a file selector in a View in django
I've managed to solve it! The problem wasn't on the csv, but on those "print" i used. It turns out command prompt on windows 8 can't print japanese letters. So, 'i've solved it by printing the output to a file instead of a command prompt -- 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/ea9693b9-bc52-4c25-a278-577c23e45321%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
utf-8' codec can't decode byte 0x93 in position 31 even though i use read().decode('utf-8') when i read a UploadedFile i get from a file selector in a View in django
I have a template called cadastrarnovomaterial.html that is a page with a textfield and a file selection button. The user should select a .csv file with the file selector. It is like this: Cadastrar um novo material 'Cadastre um novo material que pode ser usado para criar provas' {% csrf_token %} Nome: {% if nomematerialcadastrar %} {% else %} {% endif %} Arquivo csv: Then, i have the View associated with the url from the action of the above form 'terminarcadastronovomaterial'. It basically tries to first check if the .csv file is really a csv, it opens the file and starts to read it line by line: def terminarcadastronovomaterial(request): if request.method == 'POST': nomematerial = request.POST['nomematerial'] arquivo = request.FILES.get('arquivocsv') if arquivo.name.endswith('.csv'): file_data = arquivo.read().decode('utf-8') lines = file_data.split("\n") for line in lines: print("nova linha") fields = line.split(";") for field in fields: if ',' in field: distratores = field.split(",") print("distratores") for distrator in distratores: print(distrator) print("fim distratores") else: print(field) This code is working very well for non utf-8 characters inside de .csv. The problem is with utf-8 characters. In my .csv, i have a table and in this table there's utf-8 characters like "ônibus" and じてんしゃ. The thing is, when i run my django app and i try to read my csv, django is returning this message utf-8' codec can't decode byte 0x93 in position 31(which is "ônibus" in csv). I've tried to search and search how to use utf-8 csv reading on python, but it only leads to using open file without a file selector screen(which is the case for django). How do i solve my problem? is the file.read().decode('utf-8') correct? Should i use another thing? -- 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/2838894a-3a6b-4712-a53a-6b30ba53474f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: coming back to register user page after not filling a text field is causing the already filled text fields come with an annexed "/" at the end of the values
Solved it: If i remove the "/" from all my tags, it's solved. Before: After: On Thursday, September 21, 2017 at 2:46:36 PM UTC-3, fábio andrews rocha marques wrote: > > My register User View is like this: > > def cadastrarprofessor(request): > # if this is a POST request we need to process the form data > if request.method == 'POST': > nomeusuario = request.POST['usuario'] > nomesenha = request.POST['senha'] > nomeemail = request.POST['email'] > if not nomeusuario: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um usuário", > 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) > elif not nomesenha: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, > 'nomeusuariocadastro':nomeusuario}) > elif not nomeemail: > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, > 'nomeusuariocadastro':nomeusuario}) > elif User.objects.filter(nomeusuario).exists(): > return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': > False, 'error_message': "nome de usuário já existe", > 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario, > 'nomeemailcadastro':nomeemail}) > else: > usuarionovo = User.objects.create_user(nomeusuario, nomeemail, nomesenha) > novoprofessor = Professor(user=usuarionovo,nome=nomeusuario) > novoprofessor.save() > url = reverse('fimcadastro') > return HttpResponseRedirect(url) > > So, if a user doesn't fill all the textfields from the register page, > he'll come back to a page 'cadastro' but if he already filled a username, > email or password text fields, i wanted to make him go back to the same > page without making all textfields go blank again. > My template is like this: > > > Cadastro > > {% csrf_token %} > Usuário: > {% if nomeusuariocadastro %} > nomeusuariocadastro }}/> > {% else %} > > {% endif %} > Senha: > {% if nomesenhacadastro %} > > {% else %} > > {% endif %} > Email: > {% if nomeemailcadastro %} > > {% else %} > > {% endif %} > > > {% if cadastrorealizadocomsucesso is True %}cadastro realizado com > sucesso!{% endif %} > {% if error_message %}{{ error_message }}{% endif > %} > > For some reason, when the user returns to the same page but already did > fill a text field, it'll always return the value including some slashes. > Like on the annex, where he already informed a password(senha) and an > username(usuário), but not an email. The system informs that he must inform > an email, but check those text fields! They have slashes at the end of all > the values! How can i return the textfields without the slashes in the end? > -- 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/e5401770-84c5-415e-8c7e-54264dfaaa69%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
coming back to register user page after not filling a text field is causing the already filled text fields come with an annexed "/" at the end of the values
My register User View is like this: def cadastrarprofessor(request): # if this is a POST request we need to process the form data if request.method == 'POST': nomeusuario = request.POST['usuario'] nomesenha = request.POST['senha'] nomeemail = request.POST['email'] if not nomeusuario: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha}) elif not nomesenha: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 'nomeusuariocadastro':nomeusuario}) elif not nomeemail: return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario}) elif User.objects.filter(nomeusuario).exists(): return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 'error_message': "nome de usuário já existe", 'nomesenhacadastro':nomesenha, 'nomeusuariocadastro':nomeusuario, 'nomeemailcadastro':nomeemail}) else: usuarionovo = User.objects.create_user(nomeusuario, nomeemail, nomesenha) novoprofessor = Professor(user=usuarionovo,nome=nomeusuario) novoprofessor.save() url = reverse('fimcadastro') return HttpResponseRedirect(url) So, if a user doesn't fill all the textfields from the register page, he'll come back to a page 'cadastro' but if he already filled a username, email or password text fields, i wanted to make him go back to the same page without making all textfields go blank again. My template is like this: Cadastro {% csrf_token %} Usuário: {% if nomeusuariocadastro %} {% else %} {% endif %} Senha: {% if nomesenhacadastro %} {% else %} {% endif %} Email: {% if nomeemailcadastro %} {% else %} {% endif %} {% if cadastrorealizadocomsucesso is True %}cadastro realizado com sucesso!{% endif %} {% if error_message %}{{ error_message }}{% endif %} For some reason, when the user returns to the same page but already did fill a text field, it'll always return the value including some slashes. Like on the annex, where he already informed a password(senha) and an username(usuário), but not an email. The system informs that he must inform an email, but check those text fields! They have slashes at the end of all the values! How can i return the textfields without the slashes in the end? -- 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/5367eefd-3568-4702-ad6e-f4509c90b57c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Creating my own register User page, when i want to go back to same page but with text fields filled with previous values, i'm getting slashes(/)
My register page View is like this: Enter code here... -- 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/0447b52a-8d7c-4a65-9f18-bcd475fe128a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Creating my own user registration View and displaying "user created" on the same page after register
I'm trying to create my own View to register a new User in my website. I'm using this tutorial to help me with authentication: https://docs.djangoproject.com/en/1.11/topics/auth/default/# But my problem is: in the same View that i have my form that i use to create a new User, i want to, when a person sucessfully registers a new user, to display the message "user created!" First, my first View from my system is the login and its login.html is like this: {% csrf_token %} Usuário: Senha: Não tem cadastro? You can see that on the from the final line that i go to a url passing one argument: cadastrorealizadocomsucesso=false This is because my View called cadastro(portuguese for 'Register' in english) is like this: def cadastro(request,cadastrorealizadocomsucesso): return render(request, 'cadastro.html',{'cadastrorealizadocomsucesso': cadastrorealizadocomsucesso}) And my cadastro.html is like this: {% csrf_token %} Usuário: Senha: Email: {% if cadastrorealizadocomsucesso=="true" %}cadastro realizado com sucesso!{% endif %} Notice that last line of code: if cadastrorealizadocomsucesso is false, then the phrase "cadastro realizado com sucesso!"(it's portuguese for something like "user created!") will not display. But if it's true then it'll display. Here are my urls: urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^analisarlogin/$', views.analisarlogin, name='analisarlogin'), url(r'^cadastro/$', views.cadastro, name='cadastro'), url(r'^cadastrarprofessor/$', views.cadastrarprofessor, name='cadastrarprofessor'), url(r'^menuinicial/$', views.menuinicial, name='menuinicial'), url(r'^genericarmateriais/$', views.gerenciarmateriais, name='gerenciarmateriais'), ] The problem i'm getting is this: Reverse for 'cadastro' with keyword arguments '{'cadastrorealizadocomsucesso': ''}' not found. 1 pattern(s) tried: ['shikenapp/cadastro/$'] And django is pointing out to this line of code(from my html login.html): Não tem cadastro? is there any way i can pass the false value to my url 'cadastro' on the login.html template? I've tried to put just(without the name of the variable, just the value): Não tem cadastro? But it didn't change anything. How can i fix this code? -- 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/a71e1350-e267-4638-89cf-c3561e89bfba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.