#๐Ÿ”’ 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
placid tulipBOT
#

@trail escarp

Python help channel opened

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.

past ember
#

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 ?

trail escarp
#

it is showing me method not allowed when i am filling all details and clicking on register

past ember
#

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.

trail escarp
#

what should i do to correct it

past ember
#

Are you trying to POST to the confirmation page instead?

trail escarp
#

yes

past ember
#

Then set that page's URL as the action:

<form action="/confirmation" ...
trail escarp
#

i have already done it but it is not working

past ember
#

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.

past ember
trail escarp
#

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.

past ember
#

Also the name attrs of your form are things like "Name" and "City", but I think that's case-sensitive. ๐Ÿค”

trail escarp
#

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

wooden jasper
past ember
#

So there needs to be some consistency.

  • In confirm.html, you have {{ phonenumber }}, but you're passing context as phone=p. You need to have these names match up.
  • In register.html, the name attributes of the <input>s need to also be consistent: name, city, and phone should 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.

past ember
trail escarp
#

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

past ember
#

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)

toxic spear
placid tulipBOT
#
Python help channel closed for inactivity

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.