jrief / django-angular

Let AngularJS play well with Django
http://django-angular.awesto.com/
MIT License
1.23k stars 294 forks source link

Exception Value: 'str' object has no attribute 'path' #273

Closed jonasli closed 7 years ago

jonasli commented 7 years ago

I'm running the examples in this shipped project, following the guide in http://django-angular.readthedocs.io/en/latest/demos.html

but I got below exception ::

Environment:

Request Method: GET Request URL: http://localhost:8000/classic_form/

Django Version: 1.10.1 Python Version: 2.7.12 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.staticfiles', 'djng', 'server') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware')

Template error: In template /home/jonas/git-repos/django-angular/examples/server/templates/subscribe-form.html, error at line 0 'str' object has no attribute 'path' 1 : {% extends "base.html" %} 2 : {% load static tutorial_tags %} 3 : 4 : {% block container %} 5 :

{% block form_title %}Django's Form Submission{% endblock %}

6 :
7 :
8 :

{% block form_header %}Classic Form Submission in an AngularJS context{% endblock %}

9 :
10 :

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response

  1. response = self._get_response(request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response

  1. response = response.render()

File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in render

  1. self.content = self.rendered_content

File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in rendered_content

  1. content = template.render(context, self._request)

File "/usr/local/lib/python2.7/dist-packages/django/template/backends/django.py" in render

  1. return self.template.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render

  1. return self._render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render

  1. bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated

  1. return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render

  1. return compiled_parent._render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render

  1. bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated

  1. return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/library.py" in render

  1. output = self.func(*resolved_args, **resolved_kwargs)

File "/home/jonas/git-repos/django-angular/examples/server/templatetags/tutorial_tags.py" in active

  1. if request.path.startswith(reverse(url)):

Exception Type: AttributeError at /classic_form/ Exception Value: 'str' object has no attribute 'path'

I checked the code , looks it's caused by below code in the turorial_tags.py file, do you happen to know how can I fix it ? Thank you so much

@register.simple_tag def active(request, url): if request.path.startswith(reverse(url)): return 'active' return ''

adrienbrunet commented 7 years ago

As a really quick fix if you want to enjoy the library, replace active like so:

@register.simple_tag
def active(request, url):
    return ''

This is not a fix but you should be able to enjoy the tutorial... I'll have a closer look later.

jonasli commented 7 years ago

thank you @adrienbrunet , the workaround works, I can play with it now ...

adrienbrunet commented 7 years ago

Can't reproduce for now. Closing it... Feel free to reopen it if you encounter this bug again and have more information on how to reproduce it.

adrienbrunet commented 7 years ago

With django 1.10, we can witness this behaviour. I'm on it...

adrienbrunet commented 7 years ago

See PR #276