28๐
โ
You are posting to the same view that also serves the form. So at first, the view is called and serves the form. When you post the form, the same view gets called but this time you process the form. Thatโs why the action is empty.
๐คTimmy O'Mahony
36๐
If you want to explicitly set the action, assuming you have a variable username in your template,
<form name="form" method="post" action="{% url myview.views username %}">
or you could assign a name for the url in your urls.py so you could reference it like this:
# urls.py
urlpatterns += patterns('myview.views',
url(r'^(?P<user>\w+)/', 'myview', name='myurl'), # I can't think of a better name
)
# template.html
<form name="form" method="post" action="{% url myurl username %}">
๐คgladysbixly
- [Django]-Update only specific fields in a models.Model
- [Django]-Why does Django REST Framework provide different Authentication mechanisms
- [Django]-How Can I Disable Authentication in Django REST Framework
7๐
It should not require anything. Assuming you are at the following url:
www.yoursite.com/users/johnsmith/
Your form should be:
<form name="form" method="post" action="">
At this point, you are already in myview
with user johnsmith
. Your view should look like the following:
if request.method == 'POST':
form = MyForm(request.POST)
if form.is_valid():
# you should be able to extract inputs from the form here
else:
form = MyForm()
๐คThierry Lam
- [Django]-Redirect to Next after login in Django
- [Django]-Django โ is not a registered namespace
- [Django]-Django: SocialApp matching query does not exist
- [Django]-Django auto_now and auto_now_add
- [Django]-405 POST method not allowed
- [Django]-Does Django queryset values_list return a list object?
Source:stackexchange.com