/ fileupload /处的NoReverseMatch:未找到“视图”的反向。 “视图”不是有效的视图函数或模式名称

时间:2019-02-05 13:20:09

标签: django python-3.x django-forms django-templates django-views

我正在尝试创建文件上传页面。成功登录后,我会收到此错误。我不缺少我在StackOverflow上看到的内容。就像这样有很多帖子,但是我的代码中却没有做什么。任何帮助将不胜感激

Error during template rendering
In template /Users/mac/mrpash/csimplifypd/pd/templates/base.html, error at line 16

Exception Type: NoReverseMatch at /fileupload/
Exception Value: Reverse for 'view' not found. 'view' is not a valid view function or pattern name.

这是我的Urls.py

    from django.urls import path
from django.conf import settings
from pd.views import FileUpload, Index, GetText

urlpatterns = [
    path('', Index.index, name='login'),
    path('fileupload/', FileUpload.fileup, name='fileupload'),
    path('detected/', GetText.fileget, name='detected'),
]

我也将自己的观点分为三个不同的文件。 他们是 FileUpload.py

    from pd.forms.FileUploadForm import DocumentForm
from django.shortcuts import render, redirect
from django.conf import settings
from django.core.files.storage import FileSystemStorage


def fileup(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()

            return redirect("fileupload")

    else:
        form = DocumentForm()
    return render(request, 'pd/FileUpload.html', {'form': form})

GetText.py

from django.shortcuts import render
from pd.models.ImageUpload import Img


# Create your views here.
def fileget(request):
    if request.method == 'GET':
        imgs = Img.objects.all()

    return render(request, "pd/DetectedText.html", {'imgs': imgs})

Index.py

from django.shortcuts import render
from pd.models.UserForm import User
from pd.forms.UserForm import UserForm
from django.shortcuts import render, redirect


def index(request):
    if request.method == 'POST':
        username = request.POST.get('email')
        password = request.POST.get('password')

        u = User(username=username, password=password)
        u.save()

        return render(request, 'pd/login.html')
    else:
        return render(request, 'pd/login.html')

    return render(request, 'pd/login.html')

这是我的base.html

{% load static %}

<!DOCTYPE html>
<html>
<!--sudo lsof -t -i tcp:8000 | xargs kill -9-->

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="{% static 'pd/css/login.css' %}">
    <script src="{% static 'pd/js/login.js' %}"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
        crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
        crossorigin="anonymous"></script>
    <link rel="stylesheet" type="text/css" href="{% static 'pd/css/text.css' %}">
    <script src="{% static 'pd/js/jscript.js' %}"></script>
    <title>Login</title>

</head>

<body>

    <!-- Header Starts-->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="https://www.panasonic.com/in/"><img src="{% static 'textdetect/images/logo.png' %}"></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02"
            aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0 pl-3 company">
                <li class="nav-item active">
                    <a class="nav-link" href="#">DIGI QUOTE PRO</a>
                </li>
            </ul>

            <div class="d-inline pl-3">
                <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fa fa-user-plus" aria-hidden="true"></i> Sign Up</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fa fa-sign-in" aria-hidden="true"></i> Log In</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <!-- Header Ends-->

    {% block content %}
    {% endblock %}


    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script type="text/javascript" src="{% static 'pd/js/login.js' %}"></script>
</body>

</html>

0 个答案:

没有答案