2012-02-12 35 views
0

我正在處理我的第一個Django項目並使用django註冊和django配置文件。前者與nary一個問題很好地工作。第二個問題更加棘手。Django_Profiles不會自動創建配置文件,其他錯誤

幾個小時後,最終可以查看特定的用戶配置文件,這非常棒,以及所有配置文件的列表。

我遇到的兩個問題:創建新用戶時,django-profiles不會自動創建新配置文件。在管理員中創建用戶後,應該創建一個配置文件。這沒有發生。

此外,簡檔/ edit_profile形式導致此錯誤:

「TemplateSyntaxError在/簡檔/編輯/陷入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。不確定這個問題。

+0

要自動創建UserProfile,請查看django的文檔:https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users。 您可以使用後保存信號來生成配置文件。 至於'NoReverseMatch',這聽起來像你沒有設置URL來處理你指定的固定鏈接。你需要確保你已經包含了django-profiles urls.py – 2012-02-12 01:22:04

+0

我已經包含了url文件:\t url(r'^ profiles /',include('profiles.urls')),感謝其他信息。我會立即嘗試。正如我所說,查看特定的配置文件和列表的作品。這只是模板中的形式給予適合。 – 2012-02-12 01:25:28

回答

0

這裏是一個鏈接來幫助你做到這一點。

django-profiles the missing manual

向下滾動到沒有丟失檔案!部分。在這裏他們解釋說創建一個配置文件必須在創建User實例時用信號完成。