我看到这个问题已经问了很多遍了-但是我无法确定我在做什么错。谁能帮我找出问题所在?我在那儿有CSRF令牌,但是我觉得我在视图中一定做错了什么?
views.py
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Larger blue circle in back -->
<item>
<shape
android:shape="rectangle"
>
<solid android:color="#FFFFFF"
/>
<corners
android:topLeftRadius="30dp"
android:topRightRadius="30dp"
android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
/>
<size
android:width="89dp"
android:height="22dp"/>
<stroke android:width="1dp"
android:color="#fff" />
</shape>
</item>
<!-- Smaller red circle in front -->
<item>
<shape android:shape="oval">
<!-- transparent stroke = larger_circle_size - smaller_circle_size -->
<stroke android:color="@android:color/transparent"
android:width="5dp"/>
<solid android:color="#f00"/>
<size
android:width="5dp"
android:height="5dp"/>
<padding
android:bottom="0dp"
android:left="10dp"
android:right="40dp"
android:top="0dp"
/>
</shape>
</item>
</layer-list>
register.html
if request.method == "POST":
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
user = authenticate(username=username, password=password)
auth_login(request, user)
return render('test.html')
else:
form = RegistrationForm()
return render(request, 'register.html', {'form': form})
答案 0 :(得分:1)
您是否在视图中使用CSRF标签? 您应该导入:
from django.views.decorators.csrf import csrf_exempt
然后在函数定义之前添加csrf_excemp,如下所示:
@login_required
@csrf_exempt
def update(request):
希望它能解决您的问题