I understand that this is never to be done. But I have a situation where I need to get something done real quick. I have to do a website where may be 200 people would register for an event. I need to present a simple registration form. Very basic functionality, register and view list of registrants. Very few hits. It would be live for about a month or so.
I know a little bit of Django which can allow me to put together this thing quickly. However, I have only worked with the Django development server.
My problem is setting up Apache to work with Django. I understand that, for Django, I need mod_wsgi installed. I have a VPS but mod_wsgi is not installed. I have asked my hosting provider to install it for me. Even if I can get mod_wsgi installed, it appears that it may take me some time to configure it and it may take a while.
I have the following questions.
Can I run this website on the Django development server? Will it hold up for very light traffic?
If I do, how do I get traffic to go from port 80 to the development server port. From the landing page, I can have the port number added to all the subsequent URLs.
I would also appreciate some guidance on getting Django to work with mod_wsgi.
Thanks
I use cloud9 for development. It is essentially a cloud ubuntu 14 virtual box, so it gives you a real url when django server is running (on port 80). Another use case of cloud 9 is for university classes, which is similar to your event use case. You can go there and setup your django project for free and people can find the page normally. But there are some restarts in your workspace that prevents it to be real server. If you pay 20 bucks per month they give you 2 premium workspaces that they assure that this does not happen ever. But I'm not sure if this is a good idea. I could not even imagine what kind of errors would you get if all 200 people chose to login at the same time, for example.
Another way to go is making a free amazon AWS account (or digital ocean) and doing your deploy there. AWS have 1 year free trial if you run only one microinstance with a particular setup which is plenty of time for your use case. I open the instance on AWS and SSH into it with cloud 9, so it feels like developing even in production. I'm far from a devops expert but I could deploy Nginx, gunicorn, django in AWS following this tutorial. You can do it too for sure, but is a lot of work.
Left my prefered choice for your use case to the end: pythonanywhere. It has free trial and it's really easy to setup. You follow some very basic steps (doing stuff with mod_wsgi that I still dont understand) and make it work in minutes. It's a whole business dedicated to serve python programs.
Hope this helps
Related
So I recently finished my python project, grabbing values from an API and put it into my website.
Now I have no clue how I actually start the website (finding a host) and making it accessible to other people, I thought turning to here might find the solution.
I have done a good amount of research, tried "pythonanywhere" and "google app engine" but seem to not really find a solution.
I was hoping to be able to use "hostinger" as a host, as they have a good price and a good host. Contacted them but they said that they couldn't, though I could upload it to a VPS (which they have). Would it work for me to upload my files to this VPS and therefor get it to a website? or should I use another host?
I just deployed my first app and used Heroku. I'm very happy with it so far and it was fairly straight forward to set up. It does require a basic git understanding but was not hard to learn
A VPS would work, but you'll need to understand basic linux server admin to get things setup properly.
Sounds like you don't have any experience with server admin, so something like App Engine would be great for you. There are a ton of tutorials on the internet for deploying flask to GAE.
I have developed a few python programs that I want to make available online.
I am new to web services, and I am not sure what I need to do in order to create a service where somebody makes a request to an URL (for example), and the URL triggers a Python program that displays something in the user's browser, or a set of inputs are given to the program via browser, and then python does whatver it is supposed to do.
I was playing with the google app engine, which runs fine with the tutorial, and was planning to use it becuase it looks easy, but the problem with GAE is that it does not work well (or does not work at all) with some libraries that I plan to use.
I guess what I am trying to do is some sort of API using my WebFaction account.
Can anybody point me in the right directions? What choices do I have in WebFaction? What are the easiest tools available?
Thank you very much for your help in advance.
Cheers
Well, your question is a little bit generic, but here are a few pointers/tips:
Webfaction allows you to install pretty much anything you want (you need to compile it / or ask the admins to install some CentOS package for you).
They provide some default Apache server with mod_wsgi, so you can run web2py, Django or any other wsgi frameworks.
Most popular Python web frameworks have available installers in Webfaction (web2py, django...), so I would recommend you to go with one of them.
I would also install supervisord to keep your service running after some reboot/crash/problem.
I would be glad to help you if you have any specific question...
What I want to know are actually 2 things.
Part 1:
I have a developed source code for an application in python that uses Django framework.
What I want is to be able to run the code on a developer machine and see the result. What do I need for it?
(my guesses):
Python development enironment (Eclipse/PyDev/Aptana Studio 3 seem to be the better ones for windows not sure linux yet),
I also have a postgre database already setup (I know there's a file where I have to specify connection information)
- something installed from django or would this be already included in the code that I have?
Part II:
I also want to make a dev server accessible through internet.
- this is the major part of the question and the most important. How do I publish the app?
- I have a linux machine that I would do this on, but unsure of all the things I need. Apache server?
To answer your questions:
What you need: A list of requirements and instructions to get started with Django is available here: http://djangobook.com/en/2.0/chapter02/.
Database: that chapter also includes a section on configuring access to your database, with a specific section on postgreSQL.
Dev server: To start a basic development server, see this tutorial section
Deploying django (production): For instructions on how to deploy Django for production, see chapter on deploying Django.
Publishing on internet: as for making your dev server accessible through the internet, ask on https://serverfault.com/. Make sure you provide more information about your network setup, what you've tried, what isn't working, etc. (Briefly, you need to make sure that the host you are running your server on is on a publicly accessible IP, or has port 80 forwarded to it from such a host. If in doubt, speak to your sys/network admin if you have one. Or use a django hosting service such as those listed on http://djangohosting.com)
IDE : Regarding IDE, it's down to personal preference. What you mentioned are fine and can run on Linux too.
As a first step, I suggest you follow the tutorial which guides you through the process of starting a development server and developing a basic app.
Even if your goal is to deploy an existing app, the tutorial will give you an idea of how the different components work together (apps, models, urls, templates, etc) which will help with debugging when something goes wrong with your deployment.
Good luck.
You need Python, Django, a WSGI container (e.g. mod_wsgi, uWSGI, Paste Deploy), and a database server. You make the Django project available as a WSGI app, bound to the appropriate interface on the machine.
I am developping a django app on Windows, SQLite and the django dev server . I have deployed it to my host server which is running Linux, Apache, FastCgi, MySQL.
Unfortunately, I have an error returned by the server on the prod while everything ok on the dev machine. I've asked my provider for a pre-production solution in order to be able to debug and understand the problem.
Anyway, what are according to you the most likely errors that can happen when moving a django app from dev to prod?
Best
Update: I think that a pre-prod is the best way to address this kind of problem. But I would like to build a check list of what must be done before to put in production.
Thanks for the very valuable answers that I received until now :)
Update: FYI, I 've implemented the preprod server and the email notification as suggested by shanyu and I can see that the error comes from the smart_if templatetag that I am using on this new version. Any trick with template tags?
Update: I think I've fixed the pb which was caused I think by the Filezilla FTP sending. I was using the "replace if newer" option which I guess is causing some unexpected results. Using the "replace all" option fix the issue. However, it was an opportunity for me to learn more about deployment. Thansk for your answers.
Problems I typically have include:
Misconfigured productions settings, whether in my production localsettings.py, wsgi/cgi, or apache site files in /etc/sites-available
Database differences. I use South for migrations and have run into some subtle issues when performing my migration on PostgreSQL when it worked smoothly in sqlite.
Static file hosting since I cheat and use the Django server in development
Permissions, both on the file system and within the database
Rare, but possible, network issues preventing me from getting my dependencies, whether on PyPi or some 3rd party site
Ways that I have mitigated these issues:
Use the same database in production and development (in your case, MySQL everywhere)
I've found it is useful to have a "test" environment which mimics production in every way possible (it can be on lower end hardware, or even the same machine). This way, if there are any issues in this "production-like" enivornment, I can solve them without taking my production server offline.
Script everything for repeatable deployments. I use fabric, but zc.buildout or Paver would also work. These tools help reduce typos while deploying and reduce the time to deploy my app.
Use version control (mercurial, git, subversion) and a schema migration tool (like South), so if something does go wrong when you deploy to production, you have the possibility of backing out the changes and allowing production to run on the old code with the old database schema.
I haven't set up an "egg proxy" yet, but I am considering it, to avoid issues when downloading dependencies.
I've found pip's freezing dependencies to be useful, in case a new, incompatible change to a library occurred since I downloaded it initially
Use a web testing framework like Windmill or Selenium to test my application in my "test" environment, so that I can get a lot of test coverage of my system very quickly.
Regarding your case, I can think of 2 simple things that may help you:
You can enable Django to send messages when exceptions occur giving details about them. Look at here for details.
You'll be better off if you set up a test environment on the prod server (say, test.example.com) so that you can check if things will go smoothly or not before you deploy the app.
I believe these were the podcasts I listened to recently (from Pycon 2009):
Locate Django in the Real World (PyCon 2009):
http://advocacy.python.org/podcasts/pycon.rss
Parts 1 to 3
Very good introduction to designing your apps for deployment, in particular for reuse and redeployment.
Regs.
I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements?
My automatic response would be WebFaction.
I haven't personally hosted with them, but they are primarily Python-oriented (founded by the guy who wrote CherryPy, for example, and as far as I know they were the first to roll out Python 3.0 support).
I am a big fan of Slicehost -- you get root access to a virtual server that takes about 2 minutes to install from stock OS images. The 256m slice, which has been enough for me, is US$20/mo -- it is cheaper than keeping an old box plugged in, and easy to back up. Very easy to recommend.
Plug plug for PythonAnywhere, our own modest offering in this space.
We offer free hosting for basic web apps, with 1-click config for popular frameworks like Django, Flask, Web2py etc. MySql is included, and you also get full suite of browser-based development tools like an editor and a console...
I have been using WebFaction for years and very happy with the service. They are not only python oriented. You should be able to run anything within the limitations of shared hosting (unless of course you have a dedicated server).
They are probably not the cheapest hosting service though. I don't know the prices. But I can still remember very well my previous hosting provider was unreachable for a week (not their servers, I mean the people).
I've been pretty happy with Dreamhost, and of course Google AppEngine.
Google App engine and OpenHosting.com
Have virtual server by OpenHosting, they are ultra fast with support and have very high uptime.
Check out http://pythonplugged.com/
They are trying to collect information on Python hosting providers using variuos technologies (CGI, FCGI, mod_python, mod_wsgi, etc)
I advise you to have a look at http://www.python-cloud.com
This PaaS platform can automatically scale up and down your application regarding your traffic. You can also finely customize if you want vertical, horizontal or both types of scalability. The consequence of this scaling is that you pay as you go : you only pay for your real consumption and not the potential one.
Deployment via git.
Non AWS, hosted in tier-4+ datacenters.
Free trial ;)
I use AWS micro server, 1 year free and after that you can get a 3 year reserved which works out to about $75/yr :) The micro server has only 20MB/sec throughput, ~600MB of ram, and a slower CPU. I run a few Mezzanine sites on mine and it seems fine.