Django_Profiles不会自动创建配置文件,其他错误
我正在开发我的第一个 Django 项目,并使用 django-registration 和 django-profiles。前者工作得很好,没有任何问题。第二个问题有点多。
经过几个小时后,终于可以查看特定的用户个人资料,这非常棒,还可以查看所有个人资料的列表。
我遇到的两个问题:创建新用户时,django-profiles 不会自动创建新的配置文件。在管理员中创建用户后,应该创建一个配置文件。那并没有发生。
此外,profiles/edit_profile 表单会导致以下错误:
“渲染时 /profiles/edit/ 处的TemplateSyntaxError Caught NoReverseMatch:未找到带有参数 '(,)' 和关键字参数 '{}' 的 'edit_profile' 反转。”
我一直在寻找这些问题的答案,但没有结果。
这是我的应用程序文件中的配置文件模型:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=35)
email = models.EmailField()
birth_date = models.DateField(blank=True, null=True)
city = models.CharField(max_length=25)
state = models.CharField(max_length=20)
zip_code = models.CharField(max_length=10)
def __unicode__(self):
return " %s" % (self.user)
def get_absolute_url(self):
return ('profiles_profile_detail', (), { 'username': self.user.username })
get_absolute_url = models.permalink(get_absolute_url)
这是我的表单:
class ProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
这是模板:
{% extends 'base.html' %}
{% block page_title %}Edit Profile{% endblock %}
{% block headline %}Edit Stentorian Profile{% endblock %}
{% block content %}
<form action="{% url edit_profile user %}" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
有兴趣了解我犯了哪些错误以及如何修复这些错误。 (我意识到用户对象带有名字和姓氏,但除了使用它们自己的特定字段之外,似乎没有其他方法可以将它们插入到配置文件中)。
任何见解表示赞赏。
编辑:多亏了《失踪的手册》,这似乎已经成功了。不幸的是,/profiles/edit 现在跳到/profiles/create。不确定这个问题。
I'm working on my first Django project and employing django-registration and django-profiles. The former worked beautifully with nary an issue. The second has been a bit more problematic.
After many hours, specific user profiles can finally be viewed, which is terrific, along with a list of all profiles.
The two issues I'm encountering: django-profiles will not automatically create a new profile when a new user is created. Once a user is created in the admin, a profile should be created. That isn't occurring.
In addition, the profiles/edit_profile form results in this error:
"TemplateSyntaxError at /profiles/edit/ Caught NoReverseMatch while rendering: Reverse for 'edit_profile' with arguments '(,)' and keyword arguments '{}' not found."
I've searched for answers to these issues to no avail.
This is the model for the profile in my app file:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=35)
email = models.EmailField()
birth_date = models.DateField(blank=True, null=True)
city = models.CharField(max_length=25)
state = models.CharField(max_length=20)
zip_code = models.CharField(max_length=10)
def __unicode__(self):
return " %s" % (self.user)
def get_absolute_url(self):
return ('profiles_profile_detail', (), { 'username': self.user.username })
get_absolute_url = models.permalink(get_absolute_url)
This is my form:
class ProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
This is the template:
{% extends 'base.html' %}
{% block page_title %}Edit Profile{% endblock %}
{% block headline %}Edit Stentorian Profile{% endblock %}
{% block content %}
<form action="{% url edit_profile user %}" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
Interested in learning what errors I made and how to fix these. (I realize the user object carries first and last name, but there appears no other way to insert these into the profile other than with their own specific fields).
Any insight appreciated.
Edit: It seems to have worked out thanks to The Missing Manual. Unfortunately, /profiles/edit now bounces to /profiles/create. Not sure of this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个可以帮助您完成此操作的链接。
django-profiles 缺少的手册
向下滚动到NO MISSING配置文件!部分。在这里,他们解释说,每当创建用户实例时,都必须使用信号来创建配置文件。
Here is a link to help you with this.
django-profiles the missing manual
Scroll down to NO MISSING PROFILES! section. Here they explain that to create a profile must be done with a signal whenever a User instance is created.