gpt4 book ai didi

Python方法调用,缺少参数

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:34 25 4
gpt4 key购买 nike

您好,我正在尝试实现一个分析系统,以便在用户登录后立即识别学生并从学生模型中提取信息并将其返回到主页以及系统内的每个其他页面。它还会将学生用户名附加到 URL 末尾......希望如此

我收到此错误:

profile() missing 1 required positional argument: 'username'

网址.py

    # student urls.py
# Import urls and patterns aswell as student views
from django.conf.urls import patterns, url
from student import views

urlpatterns = patterns('',
url(r'^(?P<username>[a-zA-Z0-9]+)$', views.index, name='index'),
url(r'^$', views.profile, name='profile'))

模型.py

    # student models.py
# Import the models db and validators
# Also import user information for log in identification
from django.db import models
from django.core.validators import *
from django.contrib.auth.models import User

# Specify attributes for the student database
class student(models.Model):
# Specify choices for years, gender and degree type
YEARS = (
('1', '1st'),
('2', '2nd'),
('3', '3rd'),
)
GENDER = (
('M', 'Male'),
('F', 'Female'),
)
DEGREE = (
('IT', 'Information Technology'),
('CS', 'Computer Science'),
)

# Attributes for the student model specified here
user = models.OneToOneField(User)
student_ID = models.CharField(unique=True, max_length=9, validators=[RegexValidator(regex='^[0-9]{9,9}$', message='Must be 9 unique numbers', code='nomatch')])
first_name = models.CharField(max_length=128)
middle_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
gender = models.CharField(max_length=1, choices=GENDER)
year = models.CharField(max_length=1, choices=YEARS)
degree = models.CharField(max_length=2, choices=DEGREE)
photo = models.ImageField(upload_to="profile_pictures", null=True, blank=True)

def __str__(self):
return self.student_ID

View .py

    # student views.py
# Import rendering and httpresponse
# Also import student model
from django.shortcuts import render
from django.http import HttpResponse
from student.models import student
from extra_curricular.models import extra_curricular
from module.models import module
from skill.models import skill
from django.contrib.auth.models import User

# Information box displayed on each page
def index(request, username):
user = User.objects.get(username=username)
person = student.objects.get(user=user)
return render(request, 'student/home.html', {"person":person})

#Profile page information
def profile(request, username):
user = User.objects.get(username=username)
person = student.objects.get(user=user)
experience = extra_curricular.objects.get(user=user)
module = module.objects.get(user=user)
skill = skill.objects.get(user=user)
return render(request, 'student/profile.html', {"person":person}, {"experience":experience}, {"module":module}, {"skill":skill})

首页.html

        {% block content %}
<div class = "StudentInfoMain">


</div>
<div id="Options">
<ul>
<li><a href="/student/">Home</a></li>
<li><a href="/extra_curricular/add_extra_curricular/">Add Information</a></li>
<li><a href="#">View User Profile</a></li>
<li><a href="#">Checklist</a></li>
<li><a href="/skill/add_skill/">My Skills</a></li>
<li><a href="/alumni/Find_Alumni/">Contact Alumni</a></li>
</ul>
</div>
<div class = "Homebanner">
<p>{{ user.username }}</p>
<p>{{ person.student_ID }}</p>
<p>{{ person.first_name}}</p>
<p>{{ person.last_name }}</p>
<p>{{ person.year }}</p>
<p>{{ person.degree }}</p>

</div>
<div id = "Homebody">
<p>Hello {{person.first_name}</p>
<p>Welcome to your E-Profile</p>
<br>
<p>This application is intended as an aid to you during your employment endeavours.</p>
<p>It can be used during the process of building a curriculum vitae</p>
<p>You may add information of experiences you have had during your educational career</p>
<br>
<p>For any further information: </p>
<br>


</div>


<footer>

</footer>
{% endblock %}

最佳答案

def profile(request, username):    

views.profile 需要一个额外的参数以及您尚未传递的请求。

url(r'^$', views.profile, name='profile')

关于Python方法调用,缺少参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36449020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com