我们的团队在后端使用django-rest-api进行项目工作,并在前端做出反应。对于身份验证,我们使用django-rest-auth,并且密码重置存在问题。网址:
urlpatterns += [
url(r'^accounts/', include('allauth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('api.urls')),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
url(
r'^rest-auth/password/reset/$',
PasswordResetView.as_view(),
name='password_reset',
),
url(r'^rest-auth/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
url(
r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$',
confirm,
name="account_confirm_email"
),
url(r'^', include('core.urls', namespace='core')),
]
Run Code Online (Sandbox Code Playgroud)
发布对password_reset的请求后,用户会收到包含链接的链接,其中包含uid和令牌。然后,用户以react形式填写new_password,我们要发布数据:
{
"new_password1": "new_password",
"new_password2": "new_password",
"uid": "",
"token": ""
}
Run Code Online (Sandbox Code Playgroud)
到/ rest-auth / password / reset / confirm /。
我们如何才能在前端的Make页面上获取此uid和令牌,并在此url上重置确认密码,然后发布数据以确认密码更改?
我在 django 项目中使用 postgres,对于 db 的复杂查询,我使用 connection.cursor()。今天我在过滤器中使用日期时间的原始 SQL 查询遇到问题:
with connection.cursor() as cursor:
cursor.execute(
"SELECT * from orders_orderstatus WHERE datetime > '2017-09-05 16:07:16'"
)
row = [item[0] for item in cursor.fetchall()]
return row
Run Code Online (Sandbox Code Playgroud)
结果我们有空列表。但是如果我从 psql 控制台查询,我会看到结果不为空:
SELECT * FROM orders_orderstatus WHERE datetime > '2017-09-05 16:07:16';
id | status | datetime
----+--------------------+-------------------------------+
256 | created | 2017-09-05 16:10:59.602091+07
257 | delivered | 2017-09-05 16:11:00.834547+07
258 | created | 2017-09-05 16:11:03.499364+07
Run Code Online (Sandbox Code Playgroud)
为什么 django 没有收到这个结果?