H
H
hardwellZero2015-04-11 16:07:35
Django
hardwellZero, 2015-04-11 16:07:35

How to generate random links?

Hello. Need to generate random links in Django.
I get random like this:

def random(request, size=5, chars=string.ascii_lowercase + string.digits):
      return HttpResponse(''.join(random.choice(chars) for _ in range(size)))

What needs to be done in urls and views in order to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2015-04-11
@hardwellZero

You need to add the generated identifier to the database or just keep it in memory.
urls

urlpatterns = patterns('',
    url(r'^game/(?P<id>.+)$', 'myapp.views.game_view', name='game_view'),

view
def game_view(request, id):
    # тут что-то делаем

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question