0
I’m taking a Django course that uses as a study a simplemooc platform, but I stopped in a class where when trying to access the course details that is in a separate url in a dynamic list, there is no change in the page, continues in the course listing without any change, the page only reloads. I tried to create through Course.objects.create, but nothing either. It doesn’t matter what you put after the / in 127.0.0.1:8000/courses/, whether whole, Slug or any other value, nothing changes.
The link of the first course in the comic is as: http://127.0.0.1:8000/admin/Courses/Course/13/change/
I’m guessing it’s something with the regular expression of the.py urls of Courses or some import missing. What problem?
py views.:
from django.shortcuts import render,get_object_or_404
from .models import Course
# Create your views here.
def index(request):
courses = Course.objects.all()
templateName='courses/index.html'
context = {
'courses': courses
}
return render(request,templateName, context)
def details(request,pk):
course = Course.objects.get(pk=pk)
templateName= 'courses/details.html'
context = {
'course':course
}
return render(request,templateName, context)
py urls.from Ourses:
from django.conf.urls import include,url
urlpatterns = [
url(r'^$', 'index',name='index'),
url(r'^(?P<pk>\d+)/$', 'details', name='details'),
]
simplemooc py.py urls:
from django.conf.urls import include,url
from django.contrib import admin
from simplemooc.core import views as coreViews
from simplemooc.courses import views as coursesViews
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^contato/', coreViews.contact, name="contact"),
url(r'^cursos/', coursesViews.index, name="index"),
url(r'^$', coreViews.home, name="home"),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Try editing to this url, one you have similar to it in Ourses: url(r'(?P<pk> d+)/$', 'Details', name='Details'). No at the beginning..
– Marlysson