Note that I got stuck when passing the login user's id in the form
The version of Django is 1.10.
Implemented by referring to the following for login user sign-in and login. I'm using django.contrib.auth.models and django.contrib.auth.views that Django provides by default.
http://qiita.com/maueki/items/d28fd2a170d42e745376 http://nwpct1.hatenablog.com/entry/django-oauth-twitter-facebook-github
Here, pass the id of the logged-in user as an example.
views.py
...
from django.contrib.auth.models import User
...
def test(request):
login_user_id = request.user.id
...
The following is an example of saving the login user's ID at the same time as the information passed from the template by POST.
views.py
...
from django.contrib.auth.models import User
...
def test(request):
if request.method == 'POST':
form = TestForm(request.POST)
if form.is_valid():
test = form.save(commit=False)
test.user_id = request.user.id
test.save()
return redirect('apps:templates')
else:
form = TestForm()
That's it, but it took a long time ...
Recommended Posts