I have just started with django now and was configuring urls. I am able to map different urls like /posts, /posts/create etc. Somehow I am not able to configure root url, I am not sure what wrong I am doing. Here is my configuration :
urlpatterns = [
# Examples:
url(r'',homeViews.posts),
# url(r'^blog/', include('blog.urls')),
url(r'^posts/',homeViews.posts),
url(r'^createPost/',homeViews.createPost),
url(r'^createUser/',userViews.createUser),
url(r'^post/(?P<title>[a-z,A-Z]+)/$',homeViews.post),
]`
Cheers!
here is an example, my friend.
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'home.views.home',name='index'),
url(r'^contactanos/$', 'home.views.contacto',name='contacto'),
url(r'^post/$', 'home.views.blog',name='blog')
]
Related
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
So I am following a Django tutorial and I have reached the stage where I add my own URL patterns to the urls.py file.
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url((r'^webapp/', include('webapp.urls'))),
url(r'^admin/', admin.site.urls),
]
the problem is that when I run the server Django doesnt even search for the pattern. I'm not sure what I'm doing wrong here
webapp.urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
Make sure the directory structure is:
app
app
urls.py
webapp
urls.py
You write about a file named webapp.urls.py that is unusable by django
You pass wrong arguments for url().
Wrong:
url((r'^webapp/', include('webapp.urls')))
Right:
url(r'^webapp/', include('webapp.urls'))
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')),
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
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")),
...
)