个人页面中的Django问题

nfg76nw0  于 2023-11-20  发布在  Go
关注(0)|答案(1)|浏览(136)

我在PET项目工作(紧急通知系统)
这是我的观点

from django.shortcuts import render, redirect
from django.views.generic import TemplateView
from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic.edit import CreateView
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages

####################################################

class Main(TemplateView):
    template_name = 'emnosys/main.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['css_file'] = 'styles.css'
        return context

###################################################


def Registration(request):
    if request.method == "POST":
        username = request.POST['username']
        email = request.POST['email']
        password1 = request.POST['password1']
        password2 = request.POST['password2']

        myuser = User.objects.create_user(username, email, password1)
        myuser.save()

        return redirect('signin')
    return render(request, "emnosys/registration.html")

###############################################

def Signin(request):

    if request.method == 'POST':
        username = request.POST['username']
        password1 = request.POST['pass1']

        user = authenticate(username=username, password=password1)

        if user is not None:
            login(request, user)
            return render(request, "emnosys/main.html")
        else:
            return redirect('signin')
    return render(request, "emnosys/signin.html")

################################################

def Signout(request):
    logout(request)
    return redirect('home')

######################################################

class PersonalPage(TemplateView):
    template_name = 'emnosys/personalpage.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['css_file'] = 'styles.css'
        return context

字符串
这是我的URL

from django.urls import path
from . import views
from .views import Main

urlpatterns = [
    path('', Main.as_view(), name='home'),
    path('registration/', views.Registration, name='registration'),
    path('signin/', views.Signin, name='signin'),
    path('signout/', views.Signout, name='signout'),
    path('personalpage/', views.PersonalPage, name='personalpage'),
]


这是我的个人页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../../static/emnosys/css/styles-personalpage.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="main">
        <div class="username--photo">
            <img src="https://dummyimage.com/250x250/" alt="" class="username--photo">
        </div>
        <div class="username">
            <label for="#username">Name</label>
            username
        </div>
        <div class="email">
            <label for="#email">Email</label>
            [email protected]
        </div>
        <div class="signout">
            <button type="submit" class="signout">Sign Out</button>
        </div>
    </div>
    <div class="waves">
        <img src="../../static/emnosys/images/waves.png" alt="">
    </div>
</body>
</html>


当我去浏览器,域的personalpage(http://127.0.0.1:8000/personalpage/)我看到错误

Internal Server Error: /personalpage/
Traceback (most recent call last):
  File "D:\projects\EmNoSy\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner     
    response = get_response(request)
  File "D:\projects\EmNoSy\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response 
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
[12/Nov/2023 13:06:02] "GET /personalpage/ HTTP/1.1" 500 59370


我不知道如何解决这个问题,这是非常untipically,我从来没有见过这样的问题
如果有人帮助我,我将非常感激。

nnsrf1az

nnsrf1az1#

urls.py中,你应该在基于类的视图的末尾使用as_view()

path('personalpage/', views.PersonalPage.as_view(), name='personalpage'),

字符串

相关问题