Python Forum

Full Version: Best module for creating a web based form?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi guys,
I have a requirement to code a form for my users. This form needs to be able to interact with a database to autofill fields based on user input within other fields on the form, and then submit the data etc.... something that would traditionally be done with php/javascript.

I'm not so great with php nor javascript so I was looking for a way to accomplish this using python. I already figured I could use pyodbc to connect to the db, probably the requests library - but ae there popular modules that could be useful for my form creation? and also the form-field auto-population bit? I guess I could just code in SQL statements into a configuration file and use those, but there has to be something tailor made for doing this in python.

I did some research and I've been looking into flask. Flask seems a lot like node.js in the design and implementation... does it sound like I'm on the right track? Any other suggestions for modules to use for this?

Thank you- mods if this is the wrong sub-forum for this kind of question, please feel free to move it.
(Aug-05-2020, 12:48 AM)t4keheart Wrote: [ -> ]I did some research and I've been looking into flask. Flask seems a lot like node.js in the design and implementation... does it sound like I'm on the right track?
Your on right track,but Flask is not like Node.js more like Express.js(JavaScript) Sinatra(Ruby) or Laravel(PHP).

Flask is of course fine for this task,for database use Flask-SQLAlchemy.
If want a quick setup that can test look at this post eg use of database.

Start simple if new to this just fire up(Flask come with local development web-server) a simple HTML form,then get try to get values first to server(print output).
When that work setup a database eg simple to use sqlite3 using Flask-SQLAlchemy.
right right... I really meant express.js when I said node. That's what I've used in the past to make simple web apps but even better if I can do the same thing with python and flask.

Thanks for the tips!
Obviously, you'll need to write some JavaScript for anything done client-side.
(Aug-05-2020, 04:29 PM)ndc85430 Wrote: [ -> ]Obviously, you'll need to write some JavaScript for anything done client-side.

You mean to tell me i won't be able to do anything client side with python instead of js? challenge accepted
Pretty much correct, as browsers only run JavaScript. There may be tools and libraries that let you write Python that can be transpiled to JavaScript for a browser (like you have for other languages), but I don't know if they exist or how mature they are.
(Aug-05-2020, 07:58 PM)ndc85430 Wrote: [ -> ]Pretty much correct, as browsers only run JavaScript. There may be tools and libraries that let you write Python that can be transpiled to JavaScript for a browser (like you have for other languages), but I don't know if they exist or how mature they are.

Well, that's pretty much the entire focus/point of me asking in the first place!
You can still write your backend in Python though, of course.
Well, I'm looking to replace this monster of a php/js/ajax/jquery form running on iis that's been around for probably 10 years now.
It's been around for so long, and has been modified by so many different people- with features just strapped on every which way- it's almost impossible to manage and maintain.
You change one thing on it, and something else breaks... like a big nasty spider web.

lol I was hoping for a simpler cleaner way to accomplish the same thing that ajax does- updating the content on the form without reloading the page... hopefully with flask. If I have to throw some js into the form html page itself that's fine.

I know this is a python forum, so I'm focusing primarily on what I can do with just python. plus, me not being a web developer.. or even a professional dev at all, my understanding of code syntax is most developed in python.
That can happen to software if it isn't looked after properly. Some of the books in the field that address things like this are Robert Martin's "Clean Code", Michael Feathers' "Working Effectively with Legacy Code" and Martin Fowler's "Refactoring". Of course, you need to have automated tests in place to be able to change the system safely (that's of course still true when you're writing new stuff).

One useful thing to try and do is build incrementally. You build part of the new system and have it running alongside the old one. You start migrating traffic from the old one to the new one as the latter is built out, so eventually you get to a stage where the old one is no longer serving any requests and can be safely switched off. It's referred to as the "strangler pattern" (though everything you read seems to be about replacing a monolith with microservices, we used it to replace one service with a new implementation).

If you haven't taken on a project like this before, it's a big undertaking.
Pages: 1 2