1π
I think itβs a bad idea to use the email address as primary keys. What if a user changes their email address?
It might be a better idea to have unique=True
for the email address, and let Django create the automatic primary key. Then including (?P<pk>\d+)/
in your url should work.
If you must use the email as the primary key, you need to change the regex from (?P<pk>\d+)/
, which will only match digits, to something like
(?P<pk>[\w@.-]+)
The above might not catch all email addresses. I think Django contains a better character class, but I canβt find it at the moment.
0π
I think you are just doing it in a wrong way.
Here is what you need to do:
First of all Iβd recommend you to add a pk to your model, as having email as a pk
is a bad idea.
- Create a
url
for update view
An example:
url(r'^profile/(?P<pk>[\d]+)/edit/$',
views.ProfileUpdateView.as_view(), name='edit_profile')
- Create an
UpdateView
An example:
class ProfileUpdateView(UpdateView):
model = Freelancer
fields = ['email']
template_name = "profiles/profile_edit.html"
- Create a template for the form
An example:
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
Now you need to add this link wherever you want:
<a href="{% url 'edit_profile' profile.pk %}">Edit</a>
When you vist the url you will go to update page.