Created
October 18, 2011 17:08
-
-
Save tofumatt/1295969 to your computer and use it in GitHub Desktop.
py-vs-ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python: | |
from django.shortcuts import render | |
from django.http import HttpResponse | |
def about(request): | |
return render(request, 'landing/about.html') | |
def home(request): | |
return render(request, 'landing/home.html') | |
def confirm_register(request): | |
return render(request, 'landing/confirm_register.html') | |
# Ruby: | |
['about', 'home', 'confirm_register'].each do |view| | |
return render(request, "landing/#{view}.html") | |
end |
You can probably pass things directly to render instead of using the generic view, since that's annoying to import.
Flask:
from flask import *
app = Flask(__name__)
@url.route('/about')
@url.route('/home')
@url.route('/confirm_register')
def landing():
return make_response(
render_template('landing'+request.url_rule.rule+'.html', request)
)
@RFreeburn yeah, I've done stuff like that in Sinatra too (basically what I did in my Ruby version), but this lives in a larger Django app.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, yeah, sorry, this is just code I found in an app and am refactoring; no surprise there's unused stuff there. I should have pasted a cleaner Python version.
I shall dive into generic views more now as I'm moving this stuff around anyway. Thanks. ^_^