I'm doing a Django course that uses a simplemooc platform as a study, but I stopped in a class when trying to access the details of the course that is in a separate url in a dynamic list, there is no change in the page, courses without any change, the page only reloads. I tried creating it through the Course.objects.create, but nothing too. No matter what you put after / in 127.0.0.1:8000/cursos / , be it an integer, a slug or any other value, nothing changes.
The first course link in bd is like: link
I'm thinking it's something with the urls.py regular expression of the courses or some missing import. What problem?
views.py:
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)
urls.py do courses:
from django.conf.urls import include,url
urlpatterns = [
url(r'^$', 'index',name='index'),
url(r'^(?P<pk>\d+)/$', 'details', name='details'),
]
simplemooc urls.py:
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)