This is very strange, any ideas?:
Here is my code for urls.py
from django.contrib import admin
from django.conf.urls import include
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('videos/', include('videos.urls'))
]
And videos/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path(r'^$', views.index, name='index'),
]
Actually, I fixed it! Simple mistake. Change videos\urls.py to this;
Related
My root urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('webarticles.urls')),
]
While I have seen this error answered on stackoverflow before, they don't seem to work for me. Specifically there are 2 components of the answers that confuse me:
Why url is used instead of path
If I am to import webarticles, how to do that given that my project and app are on the same level
Thank you for any help you are able to provide!
Make sure your urls.py in webarticles app has the following too:
urlpatterns = [
path('', views.index, name='index'),
]
Or whatever url list you are using in your app.
======== For Project urls.py ========
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include("webarticles.urls")),
]
======== For webarticles (app) urls.py ========
from django.urls import path
from webarticles.views import *
urlpatterns = [
path('',DemoView1,name="demo1"),
path('demo2/', DemoView2, name="demo2"),
path('demo3/', DemoView3, name="demo3"),
]
I can't get my urls to work for django no matter what I try
from django.contrib import admin
from django.urls import include, re_path
from django.conf.urls import url
from catalog import views
urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^fruit/?$', views.fruit_catalogue, name='fruit_catalogue'),
re_path(r'^fruit/?$', views.fruit_details),
re_path(r'^fruit/(?P<fruit_id>[1-7]{1})/?$', views.fruit_details),
]
There are 2 url.py files that you should check for the correct functioning of the URLs.
First the one, that is in your project, that should look something like this:
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("NAMEOFAPP.urls")),
]
and the other is inside your app. and a simple version of it should look something like this:
from django.urls import path
from . import views
urlpatterns = [
path("home", views.index, name="index"),
path("login", views.login_view, name="login"),
path("register", views.register, name="register")
]
Try to use this same setup and you should be perfectly fine.
I am just learning Django. I can't understand why "index" is being added to the empty URL. I need the address to be http://127.0.0.1:8000/, but in the address bar it immediately changes to http://127.0.0.1:8000/index/.
However, if I enter http: // localhost: 8000 / there are no such problems.
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from django.urls import include
from about import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('about.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
about app urls
from django.urls import path, re_path
from django.views.generic import RedirectView
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
The solution was very simple, it was necessary to clear the browser cache :)
I'm trying to reach the Django admin page but when I type in http://localhost:8000/admin/ it pops up with my web application instead.
For more context I have two url.py's in separate folders.
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.project_list, name='list'),
path('<slug:project_slug>/', views.project_detail, name='detail')
]
and...
from django.urls import path, include
urlpatterns = [
path('', include('budget.urls')),
path('admin/', admin.site.urls),
I'm not sure why http://localhost:8000/admin/ doesn't go to Django's admin page but if anyone has any suggestions that would be very much appreciated.
In your project level urls.py place admin url in top.
Like this
urlpatterns = [
path('admin/',admin.site.urls),
path('',include('budget.urls'))
]
Change urlpatterns order here:
from django.urls import path, include
urlpatterns = [
path('', include('budget.urls')),
path('admin/', admin.site.urls),
like this:
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('budget.urls')),
In your code pattern path('<slug:project_slug>/', views.project_detail, name='detail') resolve before path('admin',admin.site.urls),.
See Django documentation
I want to define URLs in Django but get an error:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index"),
]
the error is:
nameError(name'view' is not defind)
please inform me.
thanks,
Saeed
You need to import views. If you have an app named myapp and it has views.py inside the app directory, then import it like this:
from django.contrib import admin
from django.urls import path
from myapp import views # <--- Here
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index"),
]