Closed mondala closed 9 years ago
The URL to reverse URLs on the client is hard-coded into this middleware: https://github.com/jrief/django-angular/blob/master/djangular/middleware.py
It has to be hard-coded, because it is evaluated even before Django's URL router "sees" that URL.
I once tried to use urlpatterns
with a Redirection, but they were unable to handle POST requests.
Well yes, /angular/reverse/
url won't work if django app isn't top level. Shouldn't be the case often, but there's no hurt in supporting it.
But instead of doing it your way, I think it would be nicer to set it in config
stage. Thoughts?
Btw, step 2)
isn't required anymore.
The URL to reverse URLs on the client is hard-coded into this middleware: https://github.com/jrief/django-angular/blob/master/djangular/middleware.py
It has to be hard-coded, because it is evaluated even before Django's URL router "sees" that URL.
Hi Jrief, all I want to do is "correct" the client side because it has no way of knowing the correct top-level path to eventually build the URL, since it looks like django-angular is assuming a top level directory of '' when it could be something else. So, happily it seems there is no need to modify any Django code. The middleware will still process the path correctly because all of the top-level URL is removed from URL before attemping to match to routes.
Maybe I am missing something here. Is the lack of POST redirection a deal-killer for adding the top-level URL? I always thought that redirected POSTs were not possible since they get resent to GETs.
Well yes, /angular/reverse/ url won't work if django app isn't top level. Shouldn't be the case often, but there's no hurt in supporting it.
But instead of doing it your way, I think it would be nicer to set it in config stage. Thoughts?
Sounds good. I actually don't know what the accepted pattern is for Angular service initializations. Less code and no need to create a new .directive()
is likely better.
Btw, step 2) isn't required anymore.
I wasn't able to get it to work without including the djangular.urls.
:(
@bafflermeal did you add
MIDDLEWARE_CLASSES = (
'djangular.middleware.DjangularUrlMiddleware',
...
)
to your settings.py?
Yep.
MIDDLEWARE_CLASSES = (
'djangular.middleware.DjangularUrlMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
jrief, I apologize. I made a mistake in describing the last step in the first post above that might be the cause of some confusion. I've changed it since it made it read as if I edit in the urlRoot value in to either the JS or the Django app code, when in reality the only constant being passed is in the url-root
attribute in init-djng
in the .html file.
Commit d8028cf0093aebf65d5c0ff5473240c97c8f7526
reverse_url
can now be set like so:
myApp.config(function(djangoUrlProvider) {
djangoUrlProvider.setReverseUrl('custom.com/angular/reverse/');
});
The request path on django server has to be angular/reverse/
so middleware can detect it.
@jrief Any plans on releasing recent updates? I see your update to url middleware also hasn't been released yet?
@jkosir thanks for reminding. I just updated docs/changelog.rst, could you please add the remaining issues, then I will release 0.7.15
Done. Also updated docs, added a description of setting custom reverse url.
Suggestion: In order to use a URL whose top level is not
/
but is/myprojectname
, django-angular will try to send a URL that starts with/angular/reverse/...
. This will break the app with a 404 error. This should actually be built asmyProjectName+reverseUrl
.I fixed this in my own project:
reverseUrl
into thedjangoUrl
service as a property.djangular.urls
are included in the URLconf, such as:url(r'^angular/', include('djangular.urls', namespace='djangular')),
reverseUrl
property. For a single page I chain the following directive to the.module()
.HTML:
Angular app.js:
EDIT: Deleted a step here that was wrong and stated to add something to "the app." It is taken care of in step 1.
With this in place, I can set
<... init-djing url-root='....'>
to myProjectName so that it's routed to the right URL.