Friday, 2 November 2012
CoffeeScript Love: Backbone.js Tutorials in CoffeeScript
Ahhhh enjoy the aroma, inhale the caffeine. If you're looking for a nice list of Backbone tutorials that use CoffeeScript then look no more - CoffeeScript Love: Backbone.js Tutorials in CoffeeScript.
Thursday, 1 November 2012
Top Python Web Frameworks - Today
| example of Python language (Photo credit: Wikipedia) |
In my previous post "My Top Ten Python Web Frameworks" from about 18months ago, I gave you my opinion of what was hot, or not, at that time. Some of those seem to have stalled now - Tipfy, GAE framework, Weblayer; while others have appeared or matured - kiss.py, web.py, wheezy.web.
Below is an alphabetic list of the active (updated this year) which I know about. There may be others out there, so please let me know in the comments at the bottom.
- Bottle now on v0.11
- CubicWeb now on v3.15.5
- Django now on v1.4
- Flask now on v0.9
- kiss.py now on v0.4.9
- Nagare now on v0.4.1
- Pyramid now on v1.3
- TurboGears now on v2.2.0
- web.py now on v0.37
- web2py now on v2.2.1
- wheezy.web now on v0.1
In my next few posts I'll be giving you a run down of what state each of them is in and try to give you some idea of how they fit your requirements.
Good luck fellow traveller.
Labels:
AJAX,
CubicWeb,
Django,
Flask,
Python,
Python Web Frameworks,
TurboGears,
Web service,
web.py
Tuesday, 17 July 2012
A First Look at Flask-Evolution
While poking around in Flask-Ahoy this morning I came across Flask-Evolution which I hadn't previous noticed. It offers the Django idea of migrations to the Flask community and so I thought I'd give it a go and see how it shapes up.
So let's set up a virtual environment and get the basics in place.
Now the contents of the two files you touched. First the "hello world" Flask app goes in the myapp.py file:
Next we we take the tutorial Flask-Script manage.py file and adapt it very slightly:
Now we are ready to create a simple migration for a Post model for a blog:
and you get the template file which looks like this:
In the file put your Post model and modfy "up" and "down":
Our First Migration
Our Second Migration
Now if we want to modify that Post model we can again do:
modify your model and modfy "up" and "down", I've left some comments so you can see what I did:
and run it again.
You should also play around with the "redo" and "undo" commands. That's about it really.
Conclusion
This is only version 0.6 of Flask-Evolution and it's got a way to go, but I can see some use in using it, but it's far from seamless and it's a long way from South.
Documentation is woeful and I'm not convinced the developer Adam Patterson has the time to do the job he'd like to.
You could always offer to give him a hand!
If you see anything wrong with what I've written here or if you spot spelling or other mistakes then please let me know.
Good luck fellow traveller.
So let's set up a virtual environment and get the basics in place.
Now the contents of the two files you touched. First the "hello world" Flask app goes in the myapp.py file:
Next we we take the tutorial Flask-Script manage.py file and adapt it very slightly:
Now we are ready to create a simple migration for a Post model for a blog:
and you get the template file which looks like this:
In the file put your Post model and modfy "up" and "down":
Our First Migration
Our Second Migration
Now if we want to modify that Post model we can again do:
modify your model and modfy "up" and "down", I've left some comments so you can see what I did:
and run it again.
You should also play around with the "redo" and "undo" commands. That's about it really.
Conclusion
This is only version 0.6 of Flask-Evolution and it's got a way to go, but I can see some use in using it, but it's far from seamless and it's a long way from South.
Documentation is woeful and I'm not convinced the developer Adam Patterson has the time to do the job he'd like to.
You could always offer to give him a hand!
If you see anything wrong with what I've written here or if you spot spelling or other mistakes then please let me know.
Sunday, 8 July 2012
Hosting Domains on Your Domestic Broadband Connection
It's not ideal, but it is possible to host your own domain(s) on your home broadband connection. Find out how.
I showed you in my previous last Nginx & uWSGI Living Together in Your Shed how to set up your own Nginx server to serve WSGI applications like Flask, Django, Bottle, Pyramid etc. This allows you to host your own applications on the cheap. All you need is any old server right?
Well sort of. I mean it's cheap enough to buy your own domain name and you probably will want to, but when you are filling in the registration what do you enter when it asks for your DNS servers?
Static IPs can be bought or leased from IP providers and this makes it possible to host your own DNS services. However most of us have dynamic IP addresses at home because our IP providers keep their costs down by buying big blocks of addresses and dynamically allocating us one from the deck each time we need one, and sometimes for their own maintenance reasons too.
This means your IP address will change from time to time.
To get around this you can use a dynamic DNS service such as freedns.afraid.org who will point your domain name at your new IP address every time it changes. Cool. Their service is simple, clear and cheap (or even free). I'll let you investigate that yourself, but the main thing is that when you buy your domain name, you need to fill in the DNS bit using the dynamic DNS server names that they provide.
The final thing is: How do you know when your dynamic IP address changes and how do you inform your dynamic DNS service when it happens? Well, for my own purposes I wrote a little script which will do this for you, it checks if your IP has changed and if it has it calls the special callback URL that freedns and others supply you with.
You can find it here: https://github.com/colwilson/dynamic-dns-updater
Good luck fellow traveller.
![]() |
| Hosting on a Budget? |
Well sort of. I mean it's cheap enough to buy your own domain name and you probably will want to, but when you are filling in the registration what do you enter when it asks for your DNS servers?
Static IPs can be bought or leased from IP providers and this makes it possible to host your own DNS services. However most of us have dynamic IP addresses at home because our IP providers keep their costs down by buying big blocks of addresses and dynamically allocating us one from the deck each time we need one, and sometimes for their own maintenance reasons too.
This means your IP address will change from time to time.
To get around this you can use a dynamic DNS service such as freedns.afraid.org who will point your domain name at your new IP address every time it changes. Cool. Their service is simple, clear and cheap (or even free). I'll let you investigate that yourself, but the main thing is that when you buy your domain name, you need to fill in the DNS bit using the dynamic DNS server names that they provide.
The final thing is: How do you know when your dynamic IP address changes and how do you inform your dynamic DNS service when it happens? Well, for my own purposes I wrote a little script which will do this for you, it checks if your IP has changed and if it has it calls the special callback URL that freedns and others supply you with.
You can find it here: https://github.com/colwilson/dynamic-dns-updater
Good luck fellow traveller.
Labels:
Django,
Domain name,
Domain Name System,
Dynamic DNS,
IP address,
Nginx,
Servers,
Uniform Resource Locator
Wednesday, 4 July 2012
Nginx & uWSGI Living Together in Your Shed
Let's assume you have just bought the memorable domain name idrinkink.org and you want to host your lovely web app on that old server in the shed.
I recently set up both Flask-Ahoy! and Django-Ahoy! on a five year old desktop my daughter was chucking out, so I can guarantee you that this configuration can handle enough traffic to get you going, or to demo products to your customers.
Before we start, I'm assuming you are familiar with python web frameworks (Django, Flask, Bottle etc) and with using virtualenv to segregate your environments. I usually use Flask as my framework of choice, so I'm using their "Hello World" app here.
Let's get started:
Now the contents of those files:
Finally copy the config into place and start the uwsgi daemon and the server up:
This of course is just the basics, but it will hopefully give you a starting point from which you can fiddle to your hearts content.
Good luck fellow traveller.
I recently set up both Flask-Ahoy! and Django-Ahoy! on a five year old desktop my daughter was chucking out, so I can guarantee you that this configuration can handle enough traffic to get you going, or to demo products to your customers.
Before we start, I'm assuming you are familiar with python web frameworks (Django, Flask, Bottle etc) and with using virtualenv to segregate your environments. I usually use Flask as my framework of choice, so I'm using their "Hello World" app here.
Let's get started:
Now the contents of those files:
Finally copy the config into place and start the uwsgi daemon and the server up:
This of course is just the basics, but it will hopefully give you a starting point from which you can fiddle to your hearts content.
Good luck fellow traveller.
Labels:
Django,
Flask,
Hello world program,
Languages,
Programming,
Python,
virtualenv,
Web Server Gateway Interface
Monday, 2 July 2012
Using Twitter As Your Flask Login Provider in 6 Lines
First off, I lied about the 6 lines, but it got you here and now you can see how simple it is yourself. There are actually 40 lines I think.
When I was building Flask Ahoy! I wanted to use Twitter as the login provider. I could spend a while boring you about why (as opposed to say Google, Facebook, OpenID or Roll-Your-Own), but I'l save that for another exciting post.
I have used the extremely handy Flask-OAuth to do all the legwork so you need to install that:
Next we need some html for users to click on to sign in and sign out. Try this simple block :
Next the real code begins. In your views module you need three views:
Finally we need a special little method which remembers your credentials:
Now for the sake of safety I'm going to point out a couple of things here:
Good luck fellow travelers.
When I was building Flask Ahoy! I wanted to use Twitter as the login provider. I could spend a while boring you about why (as opposed to say Google, Facebook, OpenID or Roll-Your-Own), but I'l save that for another exciting post.
I have used the extremely handy Flask-OAuth to do all the legwork so you need to install that:
Next we need some html for users to click on to sign in and sign out. Try this simple block :
Next the real code begins. In your views module you need three views:
- One to send you off to Twitter to get authorized (login)
- One to get the callback from Twitter and store your authorization credentials (twitter_authorized)
- One to log you out and tidy up (logout)
Finally we need a special little method which remembers your credentials:
Now for the sake of safety I'm going to point out a couple of things here:
- This scenario uses flask sessions (encrypted cookies) to store your Twitter OAuth token.
- When you logout, you are only destroying the twitter_user flag, you should probably destroy your credentials as well.
Good luck fellow travelers.
Labels:
Facebook,
Flask,
Flask-OAuth,
Google,
Login,
OAuth,
OpenID,
OpenID Foundation,
Twitter
Friday, 4 May 2012
Install Google App Engine on Ubuntu 12.04
If you want to use Google App Engine on Ubuntu there are a couple of things to note. Firstly GAE has recently moved to version 1.6.5 and secondly Ubuntu has recently released Ubuntu 12.04 (Precise Pangolin). Precise Pangolin is a Long Term Support (LTS) version of Ubuntu to come with Python 2.7 installed, and App Engine has been providing it as an option since February 2012. So if you are starting a new App Engine project, it's probably a good time to move to Python 2.7.
I'll explain briefly how you start a new project and there's a nice clean copy of the code at the bottom that you can cut and paste.
Let's get the show on the road. Choose a name for the project and create and switch to a virtual environment:
Now we need to know what the latest version of App Engine is, but as of writing it's 1.6.5:
Now let's create an App Engine app. The app will need a name that has been created in the App Engine Console:
And finally to run the development server:
I hope that this has all been of some help to you. Did I miss anything? Please comment below.
I'll explain briefly how you start a new project and there's a nice clean copy of the code at the bottom that you can cut and paste.
Let's get the show on the road. Choose a name for the project and create and switch to a virtual environment:
PROJ=py27_gae_project
mkvirtualenv ${PROJ}
cdvirtualenv
Note that note that "--no-site-packages" and "--distribute" are now the defaults for mkvirtualenv. You don't even need to use "--python=python2.7" on Ubuntu 12.04.Now we need to know what the latest version of App Engine is, but as of writing it's 1.6.5:
GAE=1.6.5
wget -O /tmp/gae.zip http://googleappengine.googlecode.com/files/google_appengine_${GAE}.zip
unzip /tmp/gae.zip
Now let's create an App Engine app. The app will need a name that has been created in the App Engine Console:
GAE_APP_NAME=dummy mkdir -p gae_app/staticNow create the app.yaml file:
echo """application: ${GAE_APP_NAME}
version: development
runtime: python27
api_version: 1
threadsafe: true
default_expiration: 7d
handlers:
- url: /static
static_dir: static
- url: .*
script: wsgi_app.app
""" > gae_app/app.yaml
And finally the app itself:
echo """import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Please replace me with a decent WSGI App Framework such as Flask')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
""" > gae_app/wsgi_app.py
And finally to run the development server:
python ./google_appengine/dev_appserver.py gae_app/
I hope that this has all been of some help to you. Did I miss anything? Please comment below.
Labels:
GAE,
GAE Framework,
Python,
Ubuntu,
Ubuntu 12.04,
VirtualEnvWrapper
Subscribe to:
Posts (Atom)
