(urls.W005) URL namespace 'LnkIn' isn't unique. - python

Hi I'm getting this error when doing my migrations or using the python manage.py runserver command.
(urls.W005) URL namespace 'LnkIn' isn't unique.You may not be able to reverse all URLs in this namespace.
This is how I have my urls.py inside my app directory (LnkIn).
from django.conf.urls import url
from . import views
app_name = 'LnkdIn'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^register/$', views.register, name='register'),
url(r'^login_user/$', views.login_user, name='login_user'),
url(r'^logout_user/$', views.logout_user, name='logout_user'),
url(r'^(?P<user_id>[0-9]+)/$', views.profile, name='profile'),
url(r'^(?P<song_id>[0-9]+)/favorite/$', views.favorite, name='favorite'),
url(r'^trabajos/$', views.trabajos, name='trabajos'),
url(r'^crear_oferta/$', views.crear_oferta, name='crear_oferta'),
url(r'^(?P<user_id>[0-9]+)/create_trabajo/$', views.create_trabajo, name='create_trabajo'),
url(r'^(?P<user_id>[0-9]+)/crear_amistad/$', views.crear_amistad, name='crear_amistad'),
url(r'^(?P<user_id>[0-9]+)/delete_trabajo/(?P<trabajo_id>[0-9]+)/$', views.delete_trabajo, name='delete_trabajo'),
url(r'^(?P<album_id>[0-9]+)/favorite_album/$', views.favorite_album, name='favorite_album'),
url(r'^(?P<album_id>[0-9]+)/delete_album/$', views.delete_album, name='delete_album'),
]
And this is how I have my urls.py in my main directory.
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^LnkdIn/', include('LnkdIn.urls')),
url(r'^', include('LnkdIn.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I really have no idea what could I've done wrong. I checked in my views and in my templates and everything seems to be fine, I don't seem to be having any typo on my urls. I've search but haven't find this error, I've seem similars one and they suggest to check not having mistakes in the urls.
I'm using Python 2.7 and Django 1.10.

You are importing LnkdIn.urls twice to your application urlpatterns.
You should only do it once, so choose either one from the section below
url(r'^LnkdIn/', include('LnkdIn.urls')),
or
url(r'^', include('LnkdIn.urls')),

Related

How to solve urls not found issue in django

I am building an app using django and notice that some new urls that i have created, the list is provided below are not being found.
I read somewhere that the slug might be the reason django cannot found the urls but i am not sure
main urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(config("ADMIN_URL"), admin.site.urls),
path("", include("core.urls", namespace="core")),
]
application urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
app_name = 'core'
urlpatterns = [
path('index/', views.index, name='index'),
path('home/', views.home, name='home'),
path('home/<slug:slug>/', views.user_lessons_details, name='user-lessons-details'),
path('home/join-transaction/', views.user_lessons_join_transaction, name='user-lessons-join-transaction'),
path('home/start-transaction/', views.new_test_epoint, name='new-test-epoint'),
path('home/draft/<slug:slug>/', views.user_lessons_core_action, name='user-lessons-draft'),
path('teachers/lessons/create/', views.merchant_lessons_create, name='teachers-lessons-create'),
path('teachers/lessons/list/', views.teachers_lessons_list, name='teachers-lessons-list'),
path('teachers/lessons/<slug:slug>/', views.teachers_lessons_details, name='teachers-lessons-details'),
path('teachers/lessons/<slug:slug>/update/', views.teachers_lessons_update, name='teachers-lessons-update'),
path('teachers/lessons/<slug:slug>/delete/', views.teachers_lessons_delete, name='teachers-lessons-delete'),
path('teachers/drafts/create/', views.teachers_core_actions_create, name='teachers-drafts-create'),
path('teachers/drafts/list/', views.teachers_core_actions_list, name='teachers-drafts-list'),
path('teachers/drafts/<slug:slug>/', views.teachers_core_actions_details, name='teachers-drafts-details'),
path('teachers/drafts/<slug:slug>/update/', views.teachers_core_actions_update, name='teachers-drafts-update'),
path('teachers/drafts/<slug:slug>/delete/', views.teachers_core_actions_delete, name='teachers-drafts-delete'),
path('teachers/home/list/', views.teachers_home_list, name='teachers-home-list'),
path('teachers/home/<slug:slug>/', views.teachers_home_details, name='teachers-home-details'),
path('teachers/home/create/course/', views.teachers_home_transaction_quote, name='teachers-home-create-course'),
path('teachers/home/create/something/', views.teachers_home_create_transaction, name='teachers-home-create-something'),
path('teachers/home/create/fields-selection/', views.teachers_home_fields_selection, name='teachers-home-fields-selection'),
# ALL THE NEW URLS BELOW return NOT FOUND in django no matter what i do
path('teachers/home/account/settings/', views.teachers_settings, name='teachers-settings'),
path('teachers/account/settings/update-password/', views.teachers_settings_update_password, name='teachers-settings-update-password'),
path('teachers/account/payments/', views.teachers_payments, name='teachers-payments'),
path('teachers/account/payments/update/', views.teachers_payments_update, name='teachers-payments-update'),
path('teachers/account/analytics', views.teachers_analytics_stuff, name='teachers-analytics-stuff')
]
How can i possibly solve this urls not found issue in django?
Please dont mind the urls meaning

How to add poll code to the django-cms url.py file?

I am new to Django-cms but I couldn't add the poll URL code to the url.py file. I follow every step in the Django-cms documentation but I still couldn't succeed can anyone help me with it.
This the documentation of the Django-cms:
integrating_applications
" Install the application from its GitHub repository using pip:
pip install git+http://git#github.com/divio/django-polls.git#egg=polls
Let’s add this application to our project. Add 'polls' to the end of INSTALLED_APPS in your project’s settings.py (see the note on The INSTALLED_APPS setting about ordering ).
Add the poll URL configuration to urlpatterns in the project’s urls.py:
urlpatterns += i18n_patterns(
re_path(r'^admin/', include(admin.site.urls)),
re_path(r'^polls/', include('polls.urls')),
re_path(r'^', include('cms.urls')),
)
Note that it must be included before the line for the django CMS URLs. django CMS’s URL pattern needs to be last, because it “swallows up” anything that hasn’t already been matched by a previous pattern. "
I had added the "polls" in the setting into the installation app code. But---
My question is where or how will put this code to the urls.py file. -- my urls.py file looks like this:
from cms.sitemaps import CMSSitemap
from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.urls import include, path
admin.autodiscover()
urlpatterns = [path("sitemap.xml", sitemap, {"sitemaps": {"cmspages": CMSSitemap}}),]
urlpatterns += i18n_patterns(
path("admin/", admin.site.urls),
path("", include("cms.urls"))
)
# This is only needed when using runserver.
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += i18n_patterns(
path("admin/", admin.site.urls),
path("polls/", include("polls.urls")),
path("", include("cms.urls"))
)
It will include all the sub-urls that are listed in your other polls/urls.py file under the "mywebsite/polls/" URL. This is the standard Django way to organize your routes: per app.

What is the correct way to link home and about page in django urls?

Right now what I am doing is this:
pages app > urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('about', views.about, name='about'),
]
project > urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
This seems to work fine. I am able to go to the homepage and the about page fine, but I have seen other people do as in the following:
project > urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
path('about/', include('pages.urls')),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
So basically, in the project urls file, the line
'path('about/', include('pages.urls')),'
is added as well as keeping the pages url the same as above.
So I was wondering what is the correct way of linking the about page in the project urls file.
If you have more than a single view and a single url for it in your app and you want to put all of them after some url prefix you put that prefix in urls.py root.
So lets say you have products and categories views and you want them behind api prefix. That means /api/products/ and /api/categories/ then you would have in your "api" app:
from django.urls import path
from . import views
urlpatterns = [
path('products', views.products, name='products'),
path('categories', views.categories, name='categories'),
]
In your root urls.py:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
in pages app you have to create urls.py file and link the url to the view
urlpatterns = [
path('about/', views.about, name='about'),]
and in templates you can call the url with its name

Django, url not found?

I'm trying out Python Django. With eclipse pyDev. But I'm unable to simply get my first url to display.
This urls.py is from the Cr package.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
This urlspy is from the Crowd package.
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'Crowd/', include('Cr.urls'))
]
So what I've understood from this the Crowd package is the "main" webservice(?), and by using include I can whenever the regular expression matches Crowd, will pass it on to the other urls.py(Cr). But the debugger passes:
Using the URLconf defined in Crowd.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, crowd, didn't match any of these.
my views.py file
from django.shortcuts import HttpResponse
def index(request):
return HttpResponse('<h1>Hello World!</h1>')
I tried to access it with http://127.0.0.1:8000/Crowd
Below is an image of the project folder.
Can we see your settings.py file? There is a place in there where you define your project's url file. I'm assuming it's right now either not there or it's pointing to the wrong place, because Django can't find your urls.py file.
For example, in my settings.py file for one of my projects, I have:
ROOT_URLCONF = 'Freya.urls'
Where "Freya" is my project name
Just for reference, not that I know this will solve your problem, this is what (part of) my urls.py file looks like for one of my projects:
from django.conf.urls import patterns, url
import views
urlpatterns = patterns(
'',
url(r'^$', views.index, name='index'),
url(r'^login/$', views.login, name='login'),
url(r'^logout/$', views.logout, name='logout'),
)
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'Crowd/', include('Cr.urls'))
]
just use this urls.py file

Django urls.py only one app

I just started playing with Django, I love it! I followed the tutorial from the Django documentation, but have the following question:
I only have one app (polls), currently I always have localhost/polls/{urlname}
Is there a way to remove the polls keyword? So people that go to localhost automatically go to my app polls? At the moment, I have this wildcard
url(r'.*$', RedirectView.as_view(url='polls/', permanent=False), name='index'),
But this still keeps polls in the url. This is my complete urls.py file:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
url(r'.*$', RedirectView.as_view(url='polls/', permanent=False), name='index'),
)
Thanks in advance!
Just remove the polls/ prefix in the regex of the "include" url:
urlpatterns = patterns('',
url(r'^', include('polls.urls', namespace="polls")),
...
)

Categories