0

Главный urls.py

urlpatterns = [
               path('admin/', admin.site.urls),
               path('', include('articles.urls')),  # Главная страница
               path('summernote/', include('django_summernote.urls')),  # Редактор
               path('logout/', auth_views.LogoutView.as_view(), name='logout'),  # Выход из аккаунта
               path('', include('social_django.urls', namespace='social')),
               path('profile/', include('userprofile.urls')),  # Профиль
               path('likes/', include('likes.urls'))  # Лайки
              ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

У меня есть приложения articles, profile, likes. В приложении articles есть отображении главной страницы, с которой можно перейти в профиль, но, так как путь ' ' расширяется articles.urls, то, соответственно, попасть в profile невозможно. Как правильно реализовать urls, чтобы django учитывал и profile/? Я пытался уже в articles.urls расширить путём profile, но мне выдало ошибку:

django.urls.exceptions.NoReverseMatch: 'userprofile' is not a registered namespace

userprofile это app_name в урлах.

1 ответ 1

0

Чтобы работал урл profile его нужно прописать выше главной страницы, так и со всеми

urlpatterns = [
                  path('admin/', admin.site.urls),
                  path('likes/', include('likes.urls')),  # Лайки
                  path('profile/', include('userprofile.urls')),  # Профиль
                  path('logout/', auth_views.LogoutView.as_view(), name='logout'),  # Выход из аккаунта
                  path('summernote/', include('django_summernote.urls')),  # Редактор
                  path('', include('articles.urls')),  # Главная страница
                  path('', include('social_django.urls', namespace='social')),
              ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL,
                                                                                           document_root=settings.MEDIA_ROOT)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.