Skip to content

Commit

Permalink
Use route_path instead of route_url
Browse files Browse the repository at this point in the history
I'm hoping (but haven't yet confirmed) that this will let the thing work
when I use nginx as a reverse proxy -- until now, when I do that, the
short URLs look like http://localhost:8080/xyzzy, even though the
public-facing website is http://eensy.teensy.info.
  • Loading branch information
offby1 committed May 9, 2015
1 parent bc23fbf commit 0b1f1bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tinyurl/templates/homepage.mak
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="row" style="margin-bottom: 5rem;">
<div class="col-md-12">
<div class="text-center">
<form action="${request.route_url('shorten')}" method="get" style="margin-bottom: 2rem;">
<form action="${request.route_path('shorten')}" method="get" style="margin-bottom: 2rem;">
<input type="text" id="input_url" name="input_url" placeholder="Type a URL here, yo"/>
<input type="submit" value="Tiny-ify it"/>
</form>
Expand Down
8 changes: 6 additions & 2 deletions tinyurl/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

logger = logging.getLogger ('tinyurl')


def truncate(string, maxlen):
suffix = '...'
if len(string) > maxlen:
return string[:maxlen] + suffix
return string


def _recent_entries(session, request):
now = datetime.datetime.now(pytz.utc)

Expand All @@ -44,10 +46,11 @@ def _recent_entries(session, request):
yield dict(
age = age,
human_hash = e.human_hash,
short_url = request.route_url ('lengthen', human_hash=e.human_hash),
short_url = request.route_path ('lengthen', human_hash=e.human_hash),
long_url = e.long_url
)


@view_config(route_name='home', request_method='GET')
def home_GET(request):
session = DBSession()
Expand Down Expand Up @@ -79,6 +82,7 @@ def render(request, value):
r.content_type = 'text/plain'
return r


@view_config(route_name='shorten', request_method='GET')
def create_GET(request):
session = DBSession()
Expand All @@ -100,7 +104,7 @@ def create_GET(request):
DBSession.add(HashModel(human_hash=human_hash,
long_url=long_url))

short_url = request.route_url ('lengthen', human_hash=human_hash)
short_url = request.route_path ('lengthen', human_hash=human_hash)

return render(request,
{
Expand Down

0 comments on commit 0b1f1bc

Please sign in to comment.