没有找到与查询匹配的标准Django

aij0ehis  于 2023-08-08  发布在  Go
关注(0)|答案(1)|浏览(94)

我正在做一个Django项目,当我在上面的时候一切都很顺利,但是当我打开同一个项目并在服务器上运行它时,它抛出了页面错误,注意到代码中还没有找到。这是我的urls.pydjango应用程序的www.example.com页面

from django.urls import path
from student import views
from django.contrib.auth.views import LoginView

app_name = 'student'

urlpatterns = [
path('studentclick', views.studentclick_view),
path('studentlogin', LoginView.as_view(template_name='student/studentlogin.html'),name='studentlogin'),
path('studentsignup', views.student_signup_view,name='studentsignup'),
path('student-dashboard', views.student_dashboard_view,name='student-dashboard'),
path('student-exam', views.student_exam_view,name='student-exam'),
path('take-exam/<int:pk>', views.take_exam_view,name='take-exam'),
path('start-exam/<int:pk>', views.start_exam_view,name='start-exam'),

path('calculate-marks', views.calculate_marks_view,name='calculate-marks'),
path('view-result', views.view_result_view,name='view-result'),
path('check-marks/<int:pk>', views.check_marks_view,name='check-marks'),
path('student-marks', views.student_marks_view,name='student-marks'),

path('standard-list', views.StandardListView.as_view(), name='standard-list'),
#path('',views.StandardListView.as_view(),name='standard_list'),
path('<slug:slug>', views.SubjectListView.as_view(), name='subject_list'),
path('<str:standard>/<slug:slug>/', views.LessonListView.as_view(),name='lesson_list'),
path('<str:standard>/<str:slug>/create/',views.LessonCreateView.as_view(), name='lesson_create'),
path('<str:standard>/<str:subject>/<slug:slug>/', views.LessonDetailView.as_view(),name='lesson_detail'),
path('<str:standard>/<str:subject>/<slug:slug>/update',views.LessonUpdateView.as_view(),name="lesson_update"),
path('<str:standard>/<str:subject>/<slug:slug>/delete',views.LessonDeleteView.as_view(),name='lesson_delete'),

path('student-notes',views.notes, name='student-notes'), 
path('delete_note/<int:pk>',views.delete_note,name='delete-notes'),
path('notes_detail/<int:pk>',views.NotesDetailView.as_view(),name='notes-detail'),
path('student-dictionary', views.dictionary, name='student-dictionary'),
path('student-books',views.Books, name='student-books'),
path('student-todos',views.todo, name='student-todos'),

]

字符串
这是我的views.py文件代码

def Books(request):
    if request.method == 'POST':
        form = Dashboardform(request.POST)
        text = request.POST['text']
        url = "https://www.googleapis.com/books/v1/volumes?q="+text
        r = requests.get(url)
        answer = r.json()
        result_list = []
        for i in range(10):
            result_dic ={
                'title': answer['items'][i]['volumeInfo']['title'],
                'subtitle': answer['items'][i]['volumeInfo'].get('subtitle'),
                'description': answer['items'][i]['volumeInfo'].get('description'),
                'count': answer['items'][i]['volumeInfo'].get('pageCount'),
                'categories': answer['items'][i]['volumeInfo'].get('catergories'),
                'rating': answer['items'][i]['volumeInfo'].get('pageRating'),
                'thumbnail': answer['items'][i]['volumeInfo'].get('imageLinks').get('thumbnail'),
                'preview': answer['items'][i]['volumeInfo'].get('previewLink'),
            }
            result_list.append(result_dic)
            context = {
                'form':form,
                'results':result_list,
            }
        return render(request,'student/student_books.html',context)    
    else:
        form = Dashboardform()
    context = {'form':form}
    return render(request,'student/student_books.html',context)

def dictionary(request):
    if request.method == 'POST':
        form = Dashboardform(request.POST)
        text = request.POST['text']
        url = "https://api.dictionaryapi.dev/api/v2/entries/en_US/"+text
        r = requests.get(url)
        answer = r.json()
        try:
            phonetics = answer[0]['phonetics'][0]['text'],
            audio = answer[0]['phonetics'][0]['audio'],
            definition = answer[0]['meanings'][0]['definitions'][0]['definition'],
            example = answer[0]['meanings'][0]['definitions'][0]['example'],
            synonyms = answer[0]['meanings'][0]['definitions'][0]['synonyms'],
            context ={
                'form':form,
                'input' : text,
                'phonetics' : phonetics,
                'audio': audio,
                'definition': definition,
                'example': example,
                'synonyms' : synonyms,
            }
        except:
            context = {
                'form':form,
                'input' : '',
            }
        return render(request, 'student/student_dictionary.html', context)

    else:
        form = Dashboardform()
        context = {'form':form}
    return render (request,'student/student_dictionary.html', context)

detailView = generic.DetailView
def notes(request):
    if request.method =='POST':
        form = NotesForm(request.POST)
        if form.is_valid:
            notes = Notes(user=request.user,title=request.POST['title'],description=request.POST['description'],)
            notes.save()
        messages.success(request,f"Notes added from {request.user.username} successfully")
    else:
        form = NotesForm()

    notes = Notes.objects.filter(user=request.user)
    context = {'notes': notes, 'form': form}
    return render(request, 'student/student_notes.html', context)

@login_required
def delete_note (request,pk=None): 
    Notes.objects.get(id=pk).delete()
    return redirect ('student-notes'),

class NotesDetailView (detailView):
    model = Notes

def todo(request):
    return render(request, 'student/student_todos.html')


class StandardListView(ListView):
    context_object_name ='standards'
    model = Standard
    template_name = "student/standard_list_view.html"

class SubjectListView(DetailView):
    context_object_name ='standards'
    model = Standard
    template_name = "student/subject_list_view.html"

class LessonListView(DetailView):
    context_object_name = 'subjects'
    model = Subject
    template_name = "student/lesson_list_view.html"

    def get_object(self, queryset=None):
        # Override get_object to get the Subject based on the 'slug' URL parameter
        slug = self.kwargs.get('slug')
        return get_object_or_404(Subject, slug=slug)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        # Retrieve the subject object from the context
        subject = self.object

        # Get the lessons for the subject and pass them to the template
        context['lessons'] = Lesson.objects.filter(subject=subject)
        return context

class LessonDetailView(DetailView, FormView):
    context_object_name ='lessons'
    model = Lesson
    template_name = "student/lesson_detail_view.html"
    form_class = CommentForm
    second_form_class = ReplyForm

    def get_context_data(self, **kwargs):
        context = super(LessonDetailView, self).get_context_data(**kwargs)
        if 'form' not in context:
            context['form'] = self.form_class()
        if 'form2' not in context:
            context['form2'] = self.second_form_class()
        # context['comments'] = Comment.objects.filter(id=self.object.id)
        return context


错误代码是这样的

Page not found (404)
No standard found matching the query
Request Method: GET
Request URL:    http://127.0.0.1:8000/student/student-notes
Raised by:  student.views.SubjectListView
Using the URLconf defined in onlinexam.urls, Django tried these URL patterns, in this order:

admin/
teacher/
student/ studentclick
student/ studentlogin [name='studentlogin']
student/ studentsignup [name='studentsignup']
student/ student-dashboard [name='student-dashboard']
student/ student-exam [name='student-exam']
student/ take-exam/<int:pk> [name='take-exam']
student/ start-exam/<int:pk> [name='start-exam']
student/ calculate-marks [name='calculate-marks']
student/ view-result [name='view-result']
student/ check-marks/<int:pk> [name='check-marks']
student/ student-marks [name='student-marks']
student/ standard-list [name='standard-list']
student/ <slug:slug> [name='subject_list']
The current path, student/student-notes, matched the last one.

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


当它抛出错误时,它不会显示文件夹中的所有URL。

cwdobuhd

cwdobuhd1#

尝试在末尾添加“/”:

path('student-notes/',views.notes, name='student-notes'),

字符串

相关问题