Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python web development - with or without a framework [closed]

I am planning on porting a PHP application over to Python. The application is mostly about data collection and processing. The main application runs as a stand alone command line application. There is a web interface to the application which is basically a very light weight reporting interface.

I did not use a framework in the PHP version, but being new to Python, I am wondering if it would be advantageous to use something like Django or at the very least Genshi. The caveat is I do not want my application distribution to be overwhelmed by the framework parts I would need to distribute with the application.

Is using only the cgi import in Python the best way to go in this circumstance? I would tend to think a framework is too much overhead, but perhaps I'm not thinking in a very "python" way about them. What suggestions do you have in this scenario?

like image 676
Gavin M. Roy Avatar asked Sep 25 '08 20:09

Gavin M. Roy


People also ask

Does Python have a web framework?

Python Web framework is a collection of packages or modules that allow developers to write Web applications or services. With it, developers don't need to handle low-level details like protocols, sockets or process/thread management.

Can I use Python for web development without framework?

Why would you want to build a website using python with no framework here is some reasons : you want to understand how this flask , django works. want to build your own framework in the future.

Can I make a website without a framework?

So, can you build rich web apps without using frameworks? The short answer is yes. There are plenty of websites out there that are built without using a framework; GitHub and YouTube are probably the most popular ones. The long answer might be a little more complicated than you think.


2 Answers

The command-line Python, IMO, definitely comes first. Get that to work, since that's the core of what you're doing.

The issue is that using a web framework's ORM from a command line application isn't obvious. Django provides specific instructions for using their ORM from a command-line app. Those are annoying at first, but I think they're a life-saver in the long run. I use it heavily for giant uploads of customer-supplied files.

Don't use bare CGI. It's not impossible, but too many things can go wrong, and they've all been solved by the frameworks. Why reinvent something? Just use someone else's code.

Frameworks involve learning, but no real "overhead". They're not slow. They're code you don't have to write or debug.

  1. Learn some Python.

  2. Do the Django tutorial.

  3. Start to build a web app.

    a. Start a Django project. Build a small application in that project.

    b. Build your new model using the Django ORM. Create a Django unit test for the model. Be sure that it works. You'll be able to use the default admin pages and do a lot of playing around. Just don't build the entire web site yet.

  4. Get your command-line app to work using Django ORM. Essentially, you have to finesse the settings file for this app to work nicely. See the settings/configuration section.

  5. Once you've got your command line and the default admin running, you can finish the web app.

Here's the golden rule of frameworks: It's code you don't have to write, debug or maintain. Use them.

like image 146
S.Lott Avatar answered Oct 31 '22 22:10

S.Lott


You might consider using something like web.py which would be easy to distribute (since it's small) and it would also be easy to adapt your other tools to it since it doesn't require you to submit to the framework so much like Django does.

Be forewarned, however, it's not the most loved framework in the Python community, but it might be just the thing for you. You might also check out web2py, but I know less about that.

like image 24
apg Avatar answered Nov 01 '22 00:11

apg