home
join about login
Django tips and tricks

gst

Oct. 20, 2017, 11:59 a.m.

Getting KeyError on reverse while on tests

Hi, im getting this weird key error when I try to do a reverse(url) inside my function.
something like

reverse ('something') 
then I get:
site-packages/django/urls/resolvers.py", line 243, in reverse_dict
return self._reverse_dict[language_code]
KeyError: 'en'
any clue?

3439 views origin
  • gst
    Oct. 20, 2017, 3 p.m.

    I solved it!!!



    I still would like some clarification on it, but it worked when I changed reverse for reverse_lazy.


  • Robot
    Oct. 20, 2017, 3:15 p.m.

    According to the django documentation:

    https://docs.djangoproject.com/en/1.8/ref/urlresolvers/#reverse-lazy





    reverse_lazy()¶



    A lazily evaluated version of reverse().



    reverse_lazy(viewname, urlconf=None, args=None, kwargs=None, current_app=None)¶



    It is useful for when you need to use a URL reversal before your project’s URLConf is loaded. Some common cases where this function is necessary are:



    providing a reversed URL as the url attribute of a generic class-based view.

    providing a reversed URL to a decorator (such as the login_url argument for the django.contrib.auth.decorators.permission_required() decorator).

    providing a reversed URL as a default value for a parameter in a function’s signature.



    seems that your URLConf wasn't loaded yet.

    Wasn't that on the beginnin of a file, maybe out of function?




  • Sexta
    Nov. 9, 2017, 2:43 p.m.

    I have seen this happening also when there are translated strings but

     ./manage makemessages 
    have not been issued yet.

    • gst
      Nov. 15, 2018, 5:39 p.m.

      Saved my day, thanks!

GLORIA GROOVE - SEDANAPO - Orion in Red and Blue - NASA Awards Contract for Continued Operations of its Jet Propulsi - NASA Awards Contract for Aerospace Systems Modeling, Simulation - Exclusive: North Korea earned $200 million from banned exports, s - At Tranquility Base - Slava Ukraini! on Steam - Austria plans tougher sentences for crimes against women - Federer pummels Bemelmans to move closer to top spot - amizades - Noel Guarany | Sem Fronteira (1975) [Álbum Completo/Full Album] - Southern California as Seen From Apollo 7 - Hello. - Los candidatos se disputan el poderoso voto del magisterio mexica - Cetus Galaxies and Supernova - Little Planet Soyuz - This is how to train a cat :D How I Trained My Cat - Pipi das Meias Altas Portuguese vol 1 - Eu vi eu viiiii O papai noel tava na sinaleira - Climate change: 'Hothouse Earth' risks even if CO2 emissions slas - Guri de Uruguaiana fala sobre hits do Carnaval e exageros no Phot - Launching to Observe Our Sun - Tonella - revisão do limpador de parabrisa do fusca - Eclipse solar hoje! - The Extraordinary Spiral in LL Pegasi - Fallece un exdiputado federal del PRI tiroteado este fin de seman - Wozniacki passes Barty test in Madrid, Sharapova advances - Celebrating 28 Years of the Hubble Space Telescope - Dieguito - A Lesma © ℗ MÚSICA AUTORAL Ensaio - Newest Crew Launches for the International Space Station - Trump quip about North Korea's Kim sparks outcry on social media - Major League Baseball notebook: Mariners deal for Colome, Span fr -  

tutti - social network

Tutti is the simplest social network on internet. Here you can make friends, create communities, sell things, make surveys, comment and share stuff.

Antes que regrese de la casa,en otra region,de la 1 era esposa de mi viejo,una familia de hypocritas que hablan de los hijos no mas como mentirosos atrasados que paran en puntos de maniaco que se imaginan,con un resonamiento inferior de la mediana de la gente(anormales),mi madre;ni savia nada de la lampa,Y por haver dado se cuenta que iso otro doble de la llave de abajo,era de la 1 pm a las 5 pm,que yo podia venir ahora ni puedo entrar,quetal conspiracion.Y sera pa todos sus invitados que vendran desde ese momento.Al menos mi primo y su familia se quedan un poco mas en una casa de campo en Canada,del hermano de mi media prima.Porque se estan quejando,porque ellos quieren ir a mi departamento,y que mi vieja les da otras habitaciones tambien.
Y esa familia anterior de mi viejo ahora:ni les hablo,ni les hablare jamas,que desaparecen.
De toda manera mi viejo no esta de acuerdo que mi madre se junta con ellas(os)nuestras familias ni deverian hablarse.Un dia vino esa media hermana hace anos y ahora hacen problemas en mi familia.
Y de la mia,de mi primo se van a mandar a la mierda,porque dire a otra tia,la mayor,que fastidian,cansan mi vieja,su hermanita,y ella eso era lo que no quiere.
image
more