0

My coding experience is solely scientific applications with python and c, always running from the command line on my laptop or a remote server cluster. I have a command line tool (which does some simple computations based on user input) that I'd like to move onto a webpage. Users would enter parameters into text-fields, output would be computed and displayed (numbers, possibly some plots). I have no idea how to make this transition, and I'm drowning in all of the stuff I'm finding online. What is the basic outline of setting up a web-based python application?

In particular:

  • Websites are in html; how do I build an interface that can interact with computational code?
  • Does such a program run on my server (i.e. user sends parameters, server computes, displays results); or can the code be embedded in the page which is then run user-side?
  • If my code uses additional (non-standard) libraries like numpy or scipy, can those be included?
  • If my code used an extensive amount of data (i.e. a database) how would the design pattern change? Is this when Django comes in?

Edit: google app engine?

2 Answers 2

1

Your questions have long and detailed answers which will depend on your requirements. You should define your requirements and check your choices and select one which best fits.

  • You can use django or an easier/smaller web framework like bottle.py or flask to do some boilerplate stuff that each web project needs. Django is much bigger framework but it comes with users/authentication/authorization, admin panel and many other goodies built-in.
  • Your program will almost certainly run on your servers, it is considered a security risk if a web page could run programs on clients. That said, you have other options such as java applets, flash etc. Or if you can port your application to javascript, then everything is all dandy (I doubt that though).
  • See my previous answer.
  • If you are doing data mining or similar stuff that takes a long time, you can add a job to a queue and let the user see the output later on. See celery or a similar job queue. Apart from this, you can use a relational DB, a no-SQL one like mongodb etc. which all depends on your requirements. How big your data is? Is it inherently relational or not? These are all stuff you should be thinking on.
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @tayfun, that's very helpful. Could you elaborate a little on "some boilerplate stuff that each web project needs" --- this is largely what I'm unclear one... what does a web project need?
Take a look at bottle.py or django. Everything they provide are helpful in some context. You'll need cookie handling, admin panel, DB connection pooling/management, request parameters handling, user table and others in a typical web project. If you don't use a framework which abstracts it, you'll have to write them all yourself.
1

Django - or a similar web framework - actually comes in right at the start. Web frameworks include various components, but the most important part is in step 2: taking parameters and returning a response. Many, Django included, also include elements that fulfill steps 1 and 4, that is a templating system for generating HTML, and a database layer.

Generally, the way it would work in Django would be like this. You would define some URLs for your project, and associate them with views, which are basically Python code on the server. The view would take the parameters from the URL and run some Python, perhaps including numpy/scipy if that's what your project requires. It would then return a response: that response might be generated via the template system, or might be a graph output via an imaging library, etc.

I think the best way for you to see how this all fits together is to do the Django tutorial to get an idea of how it works. Then feel free to come back here with any specific questions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.