Shinyshell Community Forums > Coding > Forms in Python? |
||||||
Sign Up | Member List | New Posts | Help |
[1]
June 28 02009, 23:19 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
I'm really confused on how to get data from a form when it is submitted in Python.
#!/usr/bin/env python How would I get the data from the form when it's submitted? ______________________________ Linux | Chrome | Python | Chuck |
June 28 02009, 23:52 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
There's really two ways to do this, and this is the simpler way.
Once you become more proficient in Python, you'll write a set of functions for yourself to make this easier than it is by default. For example, I wrote the functions url_param() and param() (inspired by Perl) for Shinyshell. Here's how you'd do it, though: #!/usr/bin/python It should work |
June 29 02009, 00:44 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
I personally love url_param() and param(), lec. They're awesome!
______________________________ Lazurane |
June 30 02009, 02:01 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
Problem. I tried your code once, and it worked. I edited, didn't work. I copy/pasted the code again and uploaded, and it stopped working. What's going on?
link Chmodded and with Linux line endings. I might take a break from Python and work more on Perl, since I seem to like it more. Like this. ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 02:15 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
You probably stuffed up the line endings, in Komodo, make sure you uncheck the 'preserve line endings' tick box and then set the line endings to UNIX.
And Perl: Yuck. Python is so much cleaner... I hate the whole $variable, it's stupid and pointless. ______________________________ Lazurane |
June 30 02009, 02:18 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
Nope. Here's a screenshot: here
LF is for Unix line endings. ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 02:21 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Uh dude, your indenting the print thing. You shouldn't be.
Also, refer to the "And Perl:" part in my previous post, you probably missed it. ______________________________ Lazurane |
June 30 02009, 02:24 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
Now it is, but it still won't work
#!/usr/bin/python And Perl: Yes, Python is much cleaner, but I think the reason I like Perl more is that it reminds me of PHP. ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 02:27 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
No, you're indenting the whole thing. It should be:
By the way, to enable code highlighting use this: (code=python) (replace the curved brackets with square ones) print """ ______________________________ Lazurane |
June 30 02009, 02:32 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
I didn't see the edit.
#!/usr/bin/python Still not working. UNIX line endings and chmod 755. ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 02:45 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
June 30 02009, 02:57 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
The form appears now, but nothing happens when you submit it.
try if you want Ugh, I give up. I'll come back to Python when I buy a Python for Dummies book or extensive tutorial online (other than Think Python because that didn't teach me anything). Back to Perl. ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 04:28 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Think Python is an awesome resource, you shouldn't need anything other than it. It's sad that you've given up so easily, new languages are hard to learn and you have to stick with it to learn it. The only reason Perl is "so easy" for you is because it's so similar to PHP - and that isn't necessarily a good thing.
______________________________ Lazurane |
June 30 02009, 05:01 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
I think I'll tackle Think Python again. I'm going to the library sometime this week to check out some Python books. The Python fire in my heart has been lit again!
Python for the win! EDIT: downloaded and installed the Python interpreter on my computer (that doesn't have internet.) ______________________________ Linux | Chrome | Python | Chuck |
June 30 02009, 09:51 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
Sorry for forgetting to print the Content-Type header, I've been doing a lot of desktop python programming recently, so I kind of forgot :o
Anyway, that code should work. I was confused when it didn't work for you, so I uploaded it, and it works. I do not really know why it doesn't work for you, hmmm. |
June 30 02009, 17:17 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
I figured out why it was not working. I had put the Content-type header before the form when it should have been right after the import CGI.
Now it works! You can shoot me later. ______________________________ Linux | Chrome | Python | Chuck |
[1]
Forum Information |
||||||||||
|