Re: reverse drops the project from the url returned
Here's more information I've been able to find. Evidently there's a problem in some configurations where mod_wsgi either isn't receiving or isn't passing SCRIPT_NAME. When I use this test script in the wsgi file I get an empty string as the value for SCRIPT_NAME. And from what I gather that's where / helpdesk should be so it can be passed to django so it's aware of the full path. ** import cStringIO def application(environ, start_response): headers = [] headers.append(('Content-Type', 'text/plain')) write = start_response('200 OK', headers) input = environ['wsgi.input'] output = cStringIO.StringIO() keys = environ.keys() keys.sort() for key in keys: print >> output, '%s: %s' % (key, repr(environ[key])) print >> output output.write(input.read(int(environ.get('CONTENT_LENGTH', '0' return [output.getvalue()] * So it may not be as much a django issue as an apache/wsgi one. I'm not skilled enough to make that distinction though. For now I'm just going to serve the app from the root and move it when I learn more or the issue is fixed. I tested the admin module and I get the same problem. Wherever the / helpdesk is present in the URL everything serves properly. But when I post a form, it's dropped from the path and I get "There is no application mounted at the root of this domain. " because I have nothing mounted at the root. I assume that message is served by apache. My host Webfaction uses multiple apache applications where the first one is shared for the server. I don't get direct access to the settings for this. Only control panel access which may make some changes indirectly. I think it uses settings or maybe SymLinks? to forward the request to another instance of apache that is installed with Django on my share of the server. I have total control of that apache. So, perhaps the first apache isn't passing any value to the second one to indicate the first "mount point" is present. This would be the "SCRIPT_NAME" from what I gather. Yet another manifestation of the issue can be found by leaving off the trailing slash at the end of the url : example.com/helpdesk/support/ case/1 will automatically redirect to example.com/support/case/1/ as django adds the slash but drops the /helpdesk ...com/helpdesk results in "There is no application mounted at the root of this domain. " com/helpdesk/ renders the app since my root urls.py contains "(r'^ $', 'helpdesk.support.views.home')," to call the support app home view. I hope some of this information helps. In the mean time all the work I've had to do to "move" my code to the root has completely convinced me of the wisdom of decoupling. ;-) And at the same time the reason I'm even having the trouble is because of the use of functions like reverse to avoid hard coding views and templates to urls! Thanks for your feedback. On Jan 3, 5:50 pm, Karen Tracey wrote: > On Sun, Jan 3, 2010 at 5:15 PM, davathar wrote: > > Ramiro, thanks for the links. That other thread does seem to describe > > the same problem and results in it being identified as a bug in the > > core urlresolvers. Unfortunately the work around of "RewriteRule ^/ > > studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm > > misapplying it. > > > Either way. I'm going to drop this for now and see what happens with > > the ticket that was opened. It seems like this would be a very big > > issue if everyone using mod_wsgi had problems when using django from > > anywhere other than the root url. But there are few posts about it. > > So I'm going to start over and see if I missed something critical in > > my setup. > > Just to clarify, though it is clear you've already found it, the ticket to > watch for the problem identified in that thread is: > > http://code.djangoproject.com/ticket/12464 > > The other one (#9435) mentioned earlier describes a somewhat different > problem. The thread and ticket #12464 show a problem determining the script > name only when the PATH_INFO for the current request is completely empty. > So reverse called from (or url tag in a template rendered by) the view that > handles the root page sees a problem, when it is called as a result of a a > request for (in your case): > > ...com/helpdesk > > but not: > > com/helpdesk/ > > because in the 2nd case PATH_INFO is not empty, it is '/'. > > Based on the urls you were mentioning earlier in the thread it wasn't clear > whether the problem with reverse, in your case, is limited
Re: reverse drops the project from the url returned
Ramiro, thanks for the links. That other thread does seem to describe the same problem and results in it being identified as a bug in the core urlresolvers. Unfortunately the work around of "RewriteRule ^/ studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm misapplying it. Either way. I'm going to drop this for now and see what happens with the ticket that was opened. It seems like this would be a very big issue if everyone using mod_wsgi had problems when using django from anywhere other than the root url. But there are few posts about it. So I'm going to start over and see if I missed something critical in my setup. Thank you -Shane On Jan 3, 3:01 pm, Ramiro Morales wrote: > On Sun, Jan 3, 2010 at 4:44 PM, davathar wrote: > > Thank you for the responses so far. But I still haven't identified > > the solution to this seemingly simple issue. > > > The behavior also happens when I use the URL tag in a template like > > this "{% url case_url case.id %}" the result I get is "/support/case/ > > 1/ ". > > > So the inconsistency is that when I make a request for "http:// > >www.example.com/helpdesk/support/1/" django is correctly mapping to > > the "case" view. But while processing the "case" view and explicitly > > naming the "case_url" that points to it, any reverse lookups are not > > returning the correct URL. > > > To me it looks like a bug since I would think it would work both ways > > or neither. > > > I think it may have to do with my switch to django 1.1.1 and mod_wsgi > > from an older 1.x version with mod_python. > > > When using mod_python, this was handled like so: > > > > > SetHandler python-program > > PythonHandler django.core.handlers.modpython > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > PythonOption django.root /mysite > > PythonDebug On > > > > > But according to this: > > http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango > > "Note that the django.root option introduced in Django 1.0 alpha > > versions does not apply to mod_wsgi and is only necessary with > > mod_python, due to mod_python not setting SCRIPT_NAME correctly. " > > > So where does that leave us? does mod_wsgi need some other > > configuration? > > I'd suggest to read this recent django-users thread: > > http://groups.google.com/group/django-users/browse_frm/thread/ce14366... > > that point to this Django ticket: > > http://code.djangoproject.com/ticket/9435 > > Another suggestion: Ty dropping the project name from all the imports > and view names > when setting your mod_wsgi deployment, just make sure themodules containing > your > settings.py, urls.py and all your apps are in the python module search path. > > HTH, > > -- > Ramiro Morales | http://rmorales.net -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: {% url admin:index %} generating wrong urls
This one has bitten me too. It also manifests when using the 'reverse' function like so: return HttpResponseRedirect(reverse('admin_url')) Instead of redirecting to /studio/admin/ it redirects to /admin/ So, while /studio/admin/ resolves well, reversing the path doesn't yield the reverse. I'm using Django 1.1.1 and mod_wsgi 2.5 Unfortunately adding the rewrite rule mentioned as a work around hasn't worked for me. -Shane On Dec 29 2009, 5:31 pm, Chris Withers wrote: > Karen Tracey wrote: > > There is at least one bug open on empty PATH_INFO handling: > > >http://code.djangoproject.com/ticket/9435 > > > though it doesn't sound like it's focused on exactly the same issue, > > No, I had as thorough a look as I could and could find no issue which > directly covered this issue so submitted a new one: > > http://code.djangoproject.com/ticket/12464 > > Sadly, Trac ate the indentation :-( > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > -http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: reverse drops the project from the url returned
Thank you for the responses so far. But I still haven't identified the solution to this seemingly simple issue. The behavior also happens when I use the URL tag in a template like this "{% url case_url case.id %}" the result I get is "/support/case/ 1/ ". So the inconsistency is that when I make a request for "http:// www.example.com/helpdesk/support/1/" django is correctly mapping to the "case" view. But while processing the "case" view and explicitly naming the "case_url" that points to it, any reverse lookups are not returning the correct URL. To me it looks like a bug since I would think it would work both ways or neither. I think it may have to do with my switch to django 1.1.1 and mod_wsgi from an older 1.x version with mod_python. When using mod_python, this was handled like so: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption django.root /mysite PythonDebug On But according to this: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango "Note that the django.root option introduced in Django 1.0 alpha versions does not apply to mod_wsgi and is only necessary with mod_python, due to mod_python not setting SCRIPT_NAME correctly. " So where does that leave us? does mod_wsgi need some other configuration? On Jan 2, 10:25 pm, davathar wrote: > Bill: Tried that, but it made no difference. case is resolving ok. > The problem is with the first part "/helpdesk/" dropping off when > doing a reverse. The same behavior happens when I use the URL tag in > a template. "{% url case_url case.id %}" I get /support/case/1/ > without the /helpdesk in front of it. > > I'm pretty sure this is because I installed Django to be served not > from the root, but rather from /helpdesk/. I use WebFaction as a > host, and their control panel is where this is setup. I think it uses > SymLinks to direct the shared Apache to the private one that only > serves my Django app. But I'm not sure and can't find a way to tell > for sure. There's nothing currently in the any of the Django files > that refers to /helpdesk/ as part of the url. Yet the webserver > resolves it properly with /helpdesk/ there and not without it. > > So I think that the first Apache server is resolving the /helpdesk/ > portion of the url and then forwarding everything after that to be > handled by Django. So maybe django doesn't know about /helpdesk/ > internally. > > Surely I'm not the only person who setup django to serve from a sub > url. And WebFaction is a popular Django host. There must be some > simple setting I'm missing somewhere. Does anyone know what it is? > > Thank you in advance. > > On Dec 30 2009, 11:37 am, Bill Freeman wrote: > > > Since your urlconf is passing "case" as a named (keyword) argument, you > > (may) have to pass it that way to reverse: > > > ...reverse('case_url', kwargs={'case':case.id})... > > > Bill > > > On Mon, Dec 28, 2009 at 8:22 PM, davathar wrote: > > > I'm stuck on a "reverse" problem. The 'case' view is supposed to > > > record posted info, then reload the same page. But it's dropping the > > > first part of the URL on the redirect and I've not been able to figure > > > out why. > > > > It should be going to .com/helpdesk/support/case/1/ But it's going > > > to .com/support/case/1/ > > > > I'm sure it's something simple as I've had the problem in the past and > > > fumbled my way through it. But I can't find it this time. Hopefully > > > the below pasted lines show all the necessary detail. > > > > Anyone see my error? > > > > helpdesk.urls: > > > urlpatterns = patterns('', > > > (r'^support/', include('helpdesk.support.urls')), > > > ) > > > > helpdesk.support.urls: > > > urlpatterns = patterns('helpdesk.support.views', > > > (r'^case/(?P\d+)/$', 'case',{},'case_url' ), > > > ) > > > > helpdesk.support.views: > > > def case(request, case): > > > return HttpResponseRedirect(reverse('case_url', args=(case.id,))) > > > # Redirect back here after POST > > > > -Shane > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: reverse drops the project from the url returned
Bill: Tried that, but it made no difference. case is resolving ok. The problem is with the first part "/helpdesk/" dropping off when doing a reverse. The same behavior happens when I use the URL tag in a template. "{% url case_url case.id %}" I get /support/case/1/ without the /helpdesk in front of it. I'm pretty sure this is because I installed Django to be served not from the root, but rather from /helpdesk/. I use WebFaction as a host, and their control panel is where this is setup. I think it uses SymLinks to direct the shared Apache to the private one that only serves my Django app. But I'm not sure and can't find a way to tell for sure. There's nothing currently in the any of the Django files that refers to /helpdesk/ as part of the url. Yet the webserver resolves it properly with /helpdesk/ there and not without it. So I think that the first Apache server is resolving the /helpdesk/ portion of the url and then forwarding everything after that to be handled by Django. So maybe django doesn't know about /helpdesk/ internally. Surely I'm not the only person who setup django to serve from a sub url. And WebFaction is a popular Django host. There must be some simple setting I'm missing somewhere. Does anyone know what it is? Thank you in advance. On Dec 30 2009, 11:37 am, Bill Freeman wrote: > Since your urlconf is passing "case" as a named (keyword) argument, you > (may) have to pass it that way to reverse: > > ...reverse('case_url', kwargs={'case':case.id})... > > Bill > > On Mon, Dec 28, 2009 at 8:22 PM, davathar wrote: > > I'm stuck on a "reverse" problem. The 'case' view is supposed to > > record posted info, then reload the same page. But it's dropping the > > first part of the URL on the redirect and I've not been able to figure > > out why. > > > It should be going to .com/helpdesk/support/case/1/ But it's going > > to .com/support/case/1/ > > > I'm sure it's something simple as I've had the problem in the past and > > fumbled my way through it. But I can't find it this time. Hopefully > > the below pasted lines show all the necessary detail. > > > Anyone see my error? > > > helpdesk.urls: > > urlpatterns = patterns('', > > (r'^support/', include('helpdesk.support.urls')), > > ) > > > helpdesk.support.urls: > > urlpatterns = patterns('helpdesk.support.views', > > (r'^case/(?P\d+)/$', 'case',{},'case_url' ), > > ) > > > helpdesk.support.views: > > def case(request, case): > > return HttpResponseRedirect(reverse('case_url', args=(case.id,))) > > # Redirect back here after POST > > > -Shane > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: reverse drops the project from the url returned
I'm using mod_wsgi. which contains this to point to settings: os.environ['DJANGO_SETTINGS_MODULE'] = 'helpdesk.settings' application = WSGIHandler() My settings.py has: # ROOT_URLCONF = 'helpdesk.urls' # INSTALLED_APPS = ( # 'helpdesk.support', # ) If I manually key in example.com/helpdesk/support/case/1/ it renders the correct view. It's only on the redirect that I'm having trouble. I've got django installed as an app at example.com/helpdesk/ so it's not on the root. And I suspect this is related to the cause. But I can't find where. What I can't wrap my head around is that the url works when keyed in, but won't reverse to the same thing. On Dec 29, 12:35 am, Raja wrote: > Are you running it through a mod-python handler? From your urls.py, it > looks like it would handle ^support as the first level match and then > continue for "/case", so the reverse URL seems to be correct, i.e. / > support/case/1. > > How are you tacking the "/helpdesk" to your request initially? > > On Dec 29, 6:22 am, davathar wrote: > > > I'm stuck on a "reverse" problem. The 'case' view is supposed to > > record posted info, then reload the same page. But it's dropping the > > first part of the URL on the redirect and I've not been able to figure > > out why. > > > It should be going to .com/helpdesk/support/case/1/ But it's going > > to .com/support/case/1/ > > > I'm sure it's something simple as I've had the problem in the past and > > fumbled my way through it. But I can't find it this time. Hopefully > > the below pasted lines show all the necessary detail. > > > Anyone see my error? > > > helpdesk.urls: > > urlpatterns = patterns('', > > (r'^support/', include('helpdesk.support.urls')), > > ) > > > helpdesk.support.urls: > > urlpatterns = patterns('helpdesk.support.views', > > (r'^case/(?P\d+)/$', 'case',{},'case_url' ), > > ) > > > helpdesk.support.views: > > def case(request, case): > > return HttpResponseRedirect(reverse('case_url', args=(case.id,))) > > # Redirect back here after POST > > > -Shane -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
reverse drops the project from the url returned
I'm stuck on a "reverse" problem. The 'case' view is supposed to record posted info, then reload the same page. But it's dropping the first part of the URL on the redirect and I've not been able to figure out why. It should be going to .com/helpdesk/support/case/1/ But it's going to .com/support/case/1/ I'm sure it's something simple as I've had the problem in the past and fumbled my way through it. But I can't find it this time. Hopefully the below pasted lines show all the necessary detail. Anyone see my error? helpdesk.urls: urlpatterns = patterns('', (r'^support/', include('helpdesk.support.urls')), ) helpdesk.support.urls: urlpatterns = patterns('helpdesk.support.views', (r'^case/(?P\d+)/$', 'case',{},'case_url' ), ) helpdesk.support.views: def case(request, case): return HttpResponseRedirect(reverse('case_url', args=(case.id,))) # Redirect back here after POST -Shane -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: never_cache and firefox
Ok, so I'm sure that I violated DRY and probably a few other good programming principles, but here's what I did that worked and doesn't alter the source. It's a hack, but I'm still learning. I created a new monkey_patches.py file and copied the function from the core file and altered it. Now I just call @really_never_cache instead. try: from functools import wraps except ImportError: from django.utils.functional import wraps # Python 2.3, 2.4 fallback. from django.utils.decorators import decorator_from_middleware from django.utils.cache import patch_cache_control, add_never_cache_headers from django.middleware.cache import CacheMiddleware def really_never_cache(view_func): """ Replacement Decorator for never_cache that adds a few more headers to a response so that it will never be cached. """ def _wrapped_view_func(request, *args, **kwargs): response = view_func(request, *args, **kwargs) add_never_cache_headers(response) response['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT' response['Pragma'] = 'no-cache' response['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate' return response return wraps(view_func)(_wrapped_view_func) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: never_cache and firefox
Thank you both for your responses. I don't know if you could tell, but I was a bit frustrated by the prior discussions on this not really addressing the root of the problem. I'm glad to know I'm not *just* crazy or overly picky. In the mean time I'll try to write a wrapper for the current functionality and I'll share it here if I'm successful. I'm new to OOP and Django and not really all that great at programming anyway. But I'll see what I can figure out. Thanks, Shane On Mar 3, 7:01 pm, Malcolm Tredinnick wrote: > On Tue, 2009-03-03 at 13:48 -0800, davathar wrote: > > I'm using @never_cache as follows and IE7 has the correct behavior, > > but Firefox 3.06 allows me to view the content of all previous pages > > by clicking the back button even after going through a logout. > > [] > > > So, is this a feature waiting to be developed? Or is there a way to > > make it work right with the existing code? > > Django does a reasonable, but not sterling, job in this particular case. > We need to add a few more "no really, we seriously mean it" headers for > the don't cache situation. The GMail instance is closer to the real > thing for never caching. > > Right now Django is serving up "never_cache" as "always stale", however > browsers and intermediate caches are permitted to serve stale instance > under certain circumstances (and, when you throw in buggy > implementations, even more often than that). You're seeing the > variations of interpretation between your IE and Firefox experiments, > for example. It's a difficult area and not particularly well (and > definitely not consistently) implemented across browsers. I suspect it > might be provable that, in this case, both browsers are doing a correct > thing, if you look hard enough at the specs (particularly when you throw > in offline browsing considerations). > > In conclusiong, though, we can and will, at some point, throw in a few > more headers in this particular case. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
never_cache and firefox
I'm using @never_cache as follows and IE7 has the correct behavior, but Firefox 3.06 allows me to view the content of all previous pages by clicking the back button even after going through a logout. @never_cache @login_required() def search(request, search): Gmail has the correct behavior in firefox and IE and it's response headers look like this: Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Tue, 03 Mar 2009 20:14:58 GMT Content-Type: text/html; charset=UTF-8 Set-Cookie: GMAIL_IMP=EXPIRED; Expires=Mon, 02-Mar-2009 20:14:58 GMT; Path=/mail Content-Encoding: gzip Transfer-Encoding: chunked X-Content-Type-Options: nosniff Server: GFE/1.3 The headers I'm getting from my Django app are as follows. And as you can tell, they are missing a lot of the stuff that Gmail seems to use to stop caching. Date: Tue, 03 Mar 2009 21:12:04 GMT Server: Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color mod_python/3.3.1 Python/2.5.2 PHP/5.2.6 Expires: Tue, 03 Mar 2009 21:12:04 GMT Vary: Cookie Last-Modified: Tue, 03 Mar 2009 21:12:04 GMT Etag: "1710a9ec54f25e5074e4decf99697a44" Cache-Control: max-age=0 Content-Type: text/html; charset=utf-8 Connection: close Transfer-Encoding: chunked I've read a lot of responses on this topic. Perhaps I missed one that works. Here are the ones I can't accept. "This is a browser issue, nothing can be done" - Maybe it's a browser issue, but other sites manage it, see Gmail. "Make the user close the browser" - Relying on users to do anything is a last resort. It may be good for them to close the browser. But making that the only reliable solution is not good enough. "Use Javascript to clear the cache or some other trick" - Relying on JS being active is like relying on users. So, is this a feature waiting to be developed? Or is there a way to make it work right with the existing code? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---