2

I'm coming from a php background and now I'd like to host a Python web application on AWS but have a few questions about it.

  1. Do I need to use a framework like Django/Flask? Is there anyway I can use core Python to do the same? Back in php, although I tried learning Laravel in the middle, I was able to just use core php with apache and host up my website.
  2. Tried deploying my Python code on my AWS but got an error that application.py was missing. I'd like to know, what exactly is application.py and what is it supposed to contain? Similarly, what's wsgi.py I see here and there. Are these actual files I need to create for the web app to be hosted? Is there some specific code that has to go into them or are the pre-created files by frameworks like Django, etc? Because I could hardly find too much information on them online.

I had recently tried following this tutorial from the AWS official site but to no luck.

The reason for being reluctant to use Django is the shortage of time to learn it. But if it were to make the task of hosting a Python web app easier, I would definitely look at it. And how is the version of Python set? Because the Python codes I've written use the python3 libraries for BeautifulSoup and urllib.

I have read a lot of articles on the web but the first thing I get on searching for Python on the web or with AWS, is Django or Flask or something. How exactly does it work? When it came to php, it was simple copying the files into the /www/ folder of the server machine and I could access the website via it's url. Maybe I've read too many posts to put them all together so could someone please set it straight for me? It would be greatly appreciated!

Thanks a lot!

asked Jul 23, 2015 at 14:27

3 Answers 3

2

You will waste a lot more time trying to write a WSGI application yourself from scratch. Use a framework, it will save you a lot of time.

PHP is very different to WSGI and WSGI sits well below the level of functionality that PHP provides out of the box. PHP is more like what frameworks in Python provide. So go learn a framework. If Django seems too complicated, try Flask first.

Also don't try and do it on AWS from the outset, learn the frameworks by using the development servers they provide on your own box. Just work through their respective tutorials.

answered Jul 23, 2015 at 22:14
Sign up to request clarification or add additional context in comments.

2 Comments

+1. I remember the old days of writing Perl CGI scripts. It felt really arbitrary when deciding between "add a new parameter and "if" clause" to an existing script, or "start a new script". You spent a lot of time on low-level decisions that were really "plumbing". With modern frameworks, they give you tools to organize your application. It feels like "extra work" to follow best practices at first, but you gain huge benefits, especially when someone else takes a look at your code.
Thanks for the reply! Will go ahead with Django. Already hosted up the sample django site on ews. Works fine. Thanks for your help!
1
  1. Actually AWS Elastic Beanstalk give you pure Python (2.6/2.7/3.4) with Apache + mod_wsgi as web proxy. You can look all supported Python environment in here. So, you can use any Python web framework (such as Django, Flask, etc.) in your web app. If you can, choose common and supported framework by AWS (Django/Flask).

    You can think: Python + Apache + mod_wsgi is equivalent to PHP + Apache + mod_php.

  2. Please take a look into AWS Elastic Beanstalk documentation for how to working with Python here. Read the Deploying a Django Application or Deploying a Flask Application if you choose one of them. You need to provide what Elastic Beanstalk environment (mod_wsgi) needs.

Same as PHP, Python actually only copy and paste the files. If you want to make Python web app without framework, you need to follow the WSGI standard. You can take look into this question. In my opinion, better if you use a framework, because it handles the WSGI part for you.

answered Jul 23, 2015 at 15:31

1 Comment

Thanks for the quick reply. Am going ahead with Django for my Python development. Thanks again for making it so simple!
0

First of all this is a good blog post to start from if you are using Django

  1. I don't know much about Flask, with Django once you understand the core concepts it's not hard at all.

  2. application.py is the file that aws looks for as stated in the blog post I pointed to: By default eb assumes our wsgi file is called application.py this can be changed to your local wcgi.py file that Django makes when you start your project with django.

  3. Beware that you want to use your static url correctly so aws will read them from the right folder. I personally disagree about the way the static files configuration in the post. It's better to stay with the aws default which is "static" and just set static url in django settings to "/static/"

answered Aug 3, 2017 at 23:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.