Home > Software design >  Django: one of pages is not opening
Django: one of pages is not opening

Time:01-20

I have created two pages locally for Django site:

  1. http://127.0.0.1:8080/portfolio/
  2. http://127.0.0.1:8080/about_me/

when I want to open "http://127.0.0.1:8080/about_me/" always opens this one "http://127.0.0.1:8080/portfolio/". Do you know reason for this?

project urls.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
     path('portfolio/', include('blog.urls')),
     path('about_me/', include('blog.urls')),
    ]

app urls.py:

from . import views
from django.urls import path
from django.conf.urls import include

urlpatterns = [
    path('', views.PostList.as_view(), name='home'),
    path('about_me/', views.Portfolio.as_view(), name='about_me'),
    path('portfolio/', views.Portfolio.as_view(), name='portfolio'),
   
    path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
    path('summernote/', include('django_summernote.urls')),


    ]
# to jest dla wysiwyg
  # add condition in django urls file

from django.conf import settings
from django.conf.urls.static import static

if settings.DEBUG:
    urlpatterns  = static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

CodePudding user response:

In your urls.py both about_me and portfolio points to the same function.

path('about_me/', views.Portfolio.as_view(), name='about_me'),
path('portfolio/', views.Portfolio.as_view(), name='portfolio'),

Both urls points to your Portfolio view. So change views function name accordingly in your urls.py.

path('about_me/', views.YourAboutMeView.as_view(), name='about_me'), #<---- change this view name accordingly
path('portfolio/', views.Portfolio.as_view(), name='portfolio'),

CodePudding user response:

May be beacuse when have in app urls.py

 path('about_me/', views.Portfolio.as_view(), name='about_me'),
 path('portfolio/', views.Portfolio.as_view(), name='portfolio'),

you have used

views.Portfolio

for both about_me and portfolio

  •  Tags:  
  • Related