1

I have issue with django routes.

My url patterns:

urlpatterns = patterns('',

# user account related users
url(r'^accounts/', include('userena.urls')),
# admin
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('api.urls')),
url('^.*$', Home.as_view(), name="home"), # It's angular routing

)

I used angular-route-segment for routing.

My home page looks like:

 {% extends "base.html" %}
 {% block content %}

     <div app-view-segment="0"></div>
     </div>
 {% endblock content %}

But i need access to userena urls. If i write in browser:

 127.0.0.1:8000/accounts/signin/

All fine. But if i set this link on angular-page, i get redirect to '/'.

Link on angular page:

<div  ng-controller="MainCtrl">
<nav class="mobile-menu" ng-class="{true: 'opened', false: 'hidden'}[isOpened]">
    <ul>
        <li><a href="{[{ 'home' | routeSegmentUrl }]}"  class="link-menu-home">Browse Listings</a></li>
        <li><a href="{[{ 'contact_us' | routeSegmentUrl }]}" class="link-menu-contact-us">Contact Us</a></li>
        {% if user.is_authenticated %}
        <li><a href="{% url 'userena_signout' %}">Sign Out</a></li>
        {% else %}
        <li><a href="{% url 'userena_signin' %}" class="link-menu-sign-in">Sign In</a></li>
        {% endif %}

    </ul>
</nav>
 <div app-view-segment="0"></div>
</div>
Sasha Odegov
  • 183
  • 1
  • 11
  • Can you show the link on the angular page? – Simone Zandara Dec 06 '15 at 13:10
  • That does not say much. I need to know what's inside href. Anyway so that you now angular has its own routing and it appends its routing after the # which is ignored by the backend. – Simone Zandara Dec 06 '15 at 13:26
  • It's possible to include django routing in angular routing? – Sasha Odegov Dec 06 '15 at 14:01
  • Sure, you can but it is not clear yet what the problem is yet. It could be something else. If you are redirected to home it might also be that your last url statement is matching everything. Just make sure that "{% url 'userena_signout' %}" is sent to the backend. – Simone Zandara Dec 06 '15 at 14:08
  • Nope. I don't know why, but it's redirecting to '/'. I think, it's happens coz on angular routing: $routeProvider.otherwise({redirectTo: '/'}); And this route('/accounts/signin/) not included on angular routes – Sasha Odegov Dec 06 '15 at 14:11
  • It should not be included if it's a call for your backend. Be aware that the link must look like this www.yoursite.com/accounts/signin (to the backend) and not like this www.yoursite.com/#accounts/signin (angular routing) – Simone Zandara Dec 06 '15 at 14:14

0 Answers0