Skip to content

Instantly share code, notes, and snippets.

@tofumatt
Created October 18, 2011 17:08
Show Gist options
  • Save tofumatt/1295969 to your computer and use it in GitHub Desktop.
Save tofumatt/1295969 to your computer and use it in GitHub Desktop.
py-vs-ruby
# 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
@jbalogh
Copy link

jbalogh commented Oct 18, 2011

You can probably pass things directly to render instead of using the generic view, since that's annoying to import.

@rfreebern
Copy link

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)
    )

@tofumatt
Copy link
Author

@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