this is my github for registration page using flask but it is not working , i have done everything please help https://github.com/AnujRewar/flask_1.git
#๐ this is my github for registration page using flask but it is not working , i have done everything
35 messages ยท Page 1 of 1 (latest)
@trail escarp
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Can you be more specific about what "not working" means?
Is there an error when you run a command, or is the site just not loading...?
If I clone this, then pip install flask and python flask/new.py, I see:
So, what is the issue you're seeing?
@trail escarp ?
it is showing me method not allowed when i am filling all details and clicking on register
Ah, I see that too. ๐
So here's what's happening.
<form action="" method="post">
The action of a form is the URL that the form sends its data to.
An empty action sends it to the same address as the current page.
So you're trying to POST to the homepage.
what should i do to correct it
Are you trying to POST to the confirmation page instead?
yes
Then set that page's URL as the action:
<form action="/confirmation" ...
i have already done it but it is not working
Though I would advise adjusting the views a little for this.
Usually you expect a form can POST to the same page. The reason being, if there's a form error, you want the page to reload on the same form.
After the form submission succeeds, you should then redirect to the confirmation page as a GET request (from inside the Flask code)
The register page code should handle the form submission.
And if it succeeds, it should redirect you to the confirmation.
This may work for the time being, though, yes. ๐
can u just help me in correcting it bz earlier from a long time i am trying to correct it but i am unable , i used chatgpt and all but nothing woked.
Also the name attrs of your form are things like "Name" and "City", but I think that's case-sensitive. ๐ค
i just used this from flask import Flask, render_template, request, redirect, url_for, session
web = Flask(name)
web.secret_key = "secret_key"
@web.route('/', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
name = request.form.get('name')
city = request.form.get('city')
phone = request.form.get('phone')
# Basic validation
if not name or not city or not phone:
error = "All fields are required."
return render_template('register.html', error=error, name=name, city=city, phone=phone)
# Save to session for demonstration
session['name'] = name
session['city'] = city
session['phone'] = phone
# Redirect to confirmation
return redirect(url_for('confirmation'))
# GET request
return render_template('register.html')
@web.route('/confirmation')
def confirmation():
return render_template(
'confirm.html',
name=session.get('name'),
city=session.get('city'),
phone=session.get('phone')
)
if name == 'main':
web.run(debug=True)
it is not showing error but also not redirecting
I like how __name__ == '__main__' is just name == 'main'
So there needs to be some consistency.
- In
confirm.html, you have{{ phonenumber }}, but you're passing context asphone=p. You need to have these names match up. - In
register.html, thenameattributes of the<input>s need to also be consistent:name,city, andphoneshould work.
That's really all you need.
And the action="/confirmation".
Those changes are enough to get it functioning, so you can see how things work.
I'd advise avoiding the AI responses for now. If you can't discern whether those responses are accurate, it's just hindering your progress here.
ok
actually i am enrolled in a course which will refund me if i complete it and i am a college student so after coming from my college , i gave almost my all time in this and in django ,that was also not workin so i moved on flask topic but now this is also not working and i am not able to complete assignments of that couse ,that made me little angry and headache
I can understand Django can be overwhelming at first, but it's a much more robust framework for this type of application overall.
If you follow along with their official tutorial, it sets you up pretty well.
(I have a personal bias for Django myself, so take that as you will)
the refund thing is actually kind acool. Is there an exam at the end?
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.