Re: Virtualenv changes url reverse behaviour

33 views
Skip to first unread message

Bill Freeman

unread,
Sep 7, 2012, 6:00:15 PM9/7/12
to django...@googlegroups.com
Are you certain that you don't have an absolute path lurking somewhere
in your code?

On Fri, Sep 7, 2012 at 3:36 PM, William Hart <har...@gmail.com> wrote:
> Hi all,
> I've made a post on stack overflow, but I'm not sure if this is some kind of
> weird bug or just something silly I'm doing. (see
> http://stackoverflow.com/questions/12310608/running-virtualenv-on-django-app-kills-my-urls).
>
> Basically I have an existing app with working urls set up like the
> following:
>
> url(r'^$', 'myapp.views.Dashboard', name="dashboard"),
>
>
> And used in templates like so:
>
> {% url 'dashboard' %}
>
>
> I pip freeze > requirements.txt, and then create and activate a virtual
> environment (virtualenv venv --distribute --no-site-packges). As soon as I
> activate this virtual environment I get a NoReverseMatch error for every url
> in my application except admin urls. If I remove the single quotes from the
> url tag above, {% url dashboard %}, it works fine so I have a work around
> for the problem.
>
> I have tried all the usual stuff, reinstalling virtual environments and
> making sure the Django versions are the same inside and outside the virtual
> environment. Any thoughts?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/RZOAigB-IhsJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

William Hart

unread,
Sep 7, 2012, 7:46:29 PM9/7/12
to django...@googlegroups.com
Hi,
Thanks for the reply.  

Yes I'm fairly certain their are no absolute paths - the settings paths are all built up using os.path, and there are no paths elsewhere in the document.

Basically as far as I can tell what is happening is that the url name for 

{% url 'dashboard' %} 

is interpreted as dashboard outside of a virtual environment and is working ok, but is interpreted as 'dashboard' (with single quotes) inside a virtual environment. I'm curious I suppose as to whether this is expected behaviour or a bug.

Thanks,
Will

Bill Freeman

unread,
Sep 7, 2012, 8:12:01 PM9/7/12
to django...@googlegroups.com
Have you tried it without the quotes? None of the examples in the
docs (https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#url)
use quotes. (Which, in turn, probably means that you can't use a
variable there.)
> https://groups.google.com/d/msg/django-users/-/Fp0oftR2Ii8J.

William Hart

unread,
Sep 7, 2012, 8:21:34 PM9/7/12
to django...@googlegroups.com
Hi,
Yes as per my first and second replies and the SO link I have done it with and without quotes.  

To be clear - this is not a 'fix my code' question as I had already found the workaround before posting, the question is more whether it is expected behaviour for the {% url %} tag to act differently in and out of a virtualenv...

Thanks,
Will

Ramiro Morales

unread,
Sep 7, 2012, 9:36:39 PM9/7/12
to django...@googlegroups.com
On Fri, Sep 7, 2012 at 9:21 PM, William Hart <har...@gmail.com> wrote:
> Hi,
> Yes as per my first and second replies and the SO link I have done it with
> and without quotes.
>
> To be clear - this is not a 'fix my code' question as I had already found
> the workaround before posting, the question is more whether it is expected
> behaviour for the {% url %} tag to act differently in and out of a
> virtualenv...

Well you could start bu telling us which version(s) of Django are you using
and if you've verified they are actually the same.

You've posted five time on StackOverflow and four times on this thread
and haven't provided that rather basic piece of information.

--
Ramiro Morales

Aaron C. de Bruyn

unread,
Sep 7, 2012, 10:03:23 PM9/7/12
to django...@googlegroups.com
On Fri, Sep 7, 2012 at 12:36 PM, William Hart <har...@gmail.com> wrote:
> And used in templates like so:
> {% url 'dashboard' %}

If you want to use quotes, put:
{% load url from future %}
at the top of your template.

Newer versions of Djagno WILL eventually require quotes, and using the
'load url from future' line allows you to get a head start on it.

-A

William Hart

unread,
Sep 8, 2012, 6:06:57 AM9/8/12
to django...@googlegroups.com
You've posted five time on StackOverflow and four times on this thread 
and haven't provided that rather basic piece of information. 

Hey Ramiro, thanks for the reply... yes you are correct I haven't mentioned the version of Django I have installed.  I've experienced this on both 1.4.1 and 1.5dev.  I think I mentioned in the comments on SO that I've installed and uninstalled requirements several times using the same requirements.txt so its happening on the same version number.

Newer versions of Djagno WILL eventually require quotes, and using the 
'load url from future' line allows you to get a head start on it. 

Thanks Aaron, good to know.   I think for now I will just use the workaround of removing the quotes and renaming some urls that fail, but I suppose the purpose of posting here was to work out if I should submit a bug report... 

Thanks to everybody for your replies and help!

Will

Javier Guerra Giraldez

unread,
Sep 8, 2012, 2:46:07 PM9/8/12
to django...@googlegroups.com
On Sat, Sep 8, 2012 at 5:06 AM, William Hart <har...@gmail.com> wrote:
> Hey Ramiro, thanks for the reply... yes you are correct I haven't mentioned
> the version of Django I have installed. I've experienced this on both 1.4.1
> and 1.5dev. I think I mentioned in the comments on SO that I've installed
> and uninstalled requirements several times using the same requirements.txt
> so its happening on the same version number.

i think this is the key to your perceived inconsistency: after so many
installations and reinstalls, it seems you're getting a different
Dajngo version in each case.

try checking the specific django version from inside the code.

--
Javier
Reply all
Reply to author
Forward
0 new messages