11 Replies - 679 Views - Last Post: 17 January 2012 - 04:01 PM Rate Topic: -----

Topic Sponsor:

#1 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

How can I process Python in a HTML webpage?

Posted 10 January 2012 - 02:16 AM

In my python server I have the following login method which is connected to MySQL DB:
def login():
	#Login method
	if request.method == 'POST':
		username = request.form.get('username')
		password = request.form.get('password')

		user = User.query.filter_by(username=username, password=password).first()
		if user is None:
			return Response(status=400)
		else:
			token = random.randint(1000000000, 9999999999)
			user.token = token
			user.token_expiry_date = datetime.datetime.now() + datetime.timedelta(minutes=15)
			db.session.commit()
			return jsonify(id=user.id, user_type=user.user_type, token=token)



Now how can I use the above Python method in the below HTML form to login?

<form>
<br>
<center>
Username: <input type="text" name="username" style="background:#bfbfbf;color:#212121;border-color:#212121;" onfocus="this.style.background = '#ffffff';" onblur="this.style.background = '#bfbfbf';">
<br>
Password: <input type="password" name="password" style="background:#bfbfbf;color:#212121;border-color:#212121;" onfocus="this.style.background = '#ffffff';" onblur="this.style.background = '#bfbfbf';">
<br>
<input type="button" value="Login" onclick="Login(this.form);" style="background:#bfbfbf;color:#000000;border-color:#212121;" onmouseover="this.style.color = '#404040';" onmouseout="this.style.color = '#000000';" onfocusr="this.style.color = '#404040';" onblur="this.style.color = '#000000';">
</center>
</form>



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How can I process Python in a HTML webpage?

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: How can I process Python in a HTML webpage?

Posted 10 January 2012 - 07:07 AM

How are you working with web aspect of this? Are you using the cgi module, Django, web.py, or ...?
Was This Post Helpful? 0
  • +
  • -

#3 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

Re: How can I process Python in a HTML webpage?

Posted 10 January 2012 - 04:07 PM

View PostMotoma, on 10 January 2012 - 07:07 AM, said:

How are you working with web aspect of this? Are you using the cgi module, Django, web.py, or ...?

Thanks for posting, I don't use any of these aspects and I have never heard of any of them. However what do you think I need to use? Basically I have a python server which handles user logins/registerations and once the user logs in he chooses a bus number which is processed using the python server to retrieve longtiute and latitude coordinates from a database and these coordinates must show up on a map preferably (google maps) in my website, these coordinates must also update every 10 seconds or so.

Sorry I didn't make my question clear enough, your advice is deeply appreciated
Was This Post Helpful? 0
  • +
  • -

#4 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 08:01 AM

Does this python server have a name? Is it something you downloaded or something you wrote?
Was This Post Helpful? 0
  • +
  • -

#5 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 10:03 AM

View PostMotoma, on 11 January 2012 - 08:01 AM, said:

Does this python server have a name? Is it something you downloaded or something you wrote?

I wrote it for an android app it handles get and post requests and outputs it in JSON form
Was This Post Helpful? 0
  • +
  • -

#6 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 10:05 AM

I guess I'm not sure what you are asking for here. What is it you are trying to do that you are having trouble with?
Was This Post Helpful? 0
  • +
  • -

#7 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 10:14 AM

View PostMotoma, on 11 January 2012 - 10:05 AM, said:

I guess I'm not sure what you are asking for here. What is it you are trying to do that you are having trouble with?

Basically .. How can I link up my HTML form with my python server to login. So for example I want to register to be able to use the web service which is locating my bus on a map. By registering this will be a POST request and the username/password should be posted to the database where it's saved, at the moment me server is responsible for handling these requests and I want to know how can I connect my website to communicate with my python server. Thanks
Was This Post Helpful? 0
  • +
  • -

#8 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 10:38 AM

Perhaps we are having a problem with terminology. You say you've written a Python "server". Does this mean that you code is opening up a socket and listening for incoming HTTP connections?
  • If not, then you will need a server like Apache to listen for HTTP requests and pass them to the appropriate script.
  • If so, you will need to parse out the appropriate headers from the request, and feed them to your login function.

Was This Post Helpful? 0
  • +
  • -

#9 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

Re: How can I process Python in a HTML webpage?

Posted 11 January 2012 - 10:41 AM

View PostMotoma, on 11 January 2012 - 10:38 AM, said:

Perhaps we are having a problem with terminology. You say you've written a Python "server". Does this mean that you code is opening up a socket and listening for incoming HTTP connections?
  • If not, then you will need a server like Apache to listen for HTTP requests and pass them to the appropriate script.
  • If so, you will need to parse out the appropriate headers from the request, and feed them to your login function.

No the server doesn't listen for http requests .. I will give it a go. Thank you do much for the advice dude :)
Was This Post Helpful? 0
  • +
  • -

#10 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon


Reputation: 2567
  • View blog
  • Posts: 10,202
  • Joined: 15-July 08

Re: How can I process Python in a HTML webpage?

Posted 12 January 2012 - 08:31 AM

A server is a piece of hardware/software that listens for a device to connect and then serves HTML and Javascript. I think what you are doing is making a Python application to log into an existing website. Is THAT the case?
Was This Post Helpful? 0
  • +
  • -

#11 mido91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-February 11

Re: How can I process Python in a HTML webpage?

Posted 12 January 2012 - 11:11 AM

View PostDogstopper, on 12 January 2012 - 08:31 AM, said:

A server is a piece of hardware/software that listens for a device to connect and then serves HTML and Javascript. I think what you are doing is making a Python application to log into an existing website. Is THAT the case?

Yes exactly ... When the server is running it listens for an IP address and a port number to carry out various features such as: login, register and retrieving longtiute & latitude coordinates from the database. Is it possible to make the server client side? Meaning putting the python server code along with the HTML code .. Would that work? Thanks for posting
Was This Post Helpful? 0
  • +
  • -

#12 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon


Reputation: 2567
  • View blog
  • Posts: 10,202
  • Joined: 15-July 08

Re: How can I process Python in a HTML webpage?

Posted 17 January 2012 - 04:01 PM

OK. What you were asking originally is totally wrong with what you just said. Yes, it is possible to use Python to automate login into sites. You have to know the format of the POST request and simply mimic it with your own values.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1