我有一个在 Django 中构建的 API 中心和一个在 NextJS 中构建的前端应用程序。我目前正在对 Nextjs 中的 Django API 进行身份验证,我对最佳实践感到好奇。
目前,NextJS 应用程序将用户用户名/密码发布到端点。此端点返回用户令牌或说明问题的错误。
反应
const login = async () => {
let token = await axios.post('/api/accounts/', {
email: email,
password: password
}).then(r => r.data.token).catch(function (error) { console.log(error) })
if (token) {
router.push({
pathname: '/home/',
query: { token: token },
})
}
}
Run Code Online (Sandbox Code Playgroud)
nexjs服务器api/accounts
export default async (req, res) => {
if (req.method === 'POST') {
try {
// retrieve payment intent data
const {data} = await axios.post('https://website/api/api-token-auth/', req.body) …Run Code Online (Sandbox Code Playgroud) 从今天起,我的UpdateView作品不再可用。每当我选择图标来编辑项目时,都会出现以下错误:
EntryUpdate is missing a QuerySet. Define EntryUpdate.model, EntryUpdate.queryset, or override EntryUpdate.get_queryset().
Run Code Online (Sandbox Code Playgroud)
我以前从未有过QuerySet UpdateView,所以我不确定为什么现在要查询。我对Generic的理解UpdateView是内置了自我查询功能,但我可能是错的。
任何帮助将非常感激。
views.py
class IndexView(generic.ListView):
template_name = 'argent/index.html'
# paginate_by = 10
def get_queryset(self):
return Entry.objects.all()
def get_context_data(self, **kwargs):
ctx = super(IndexView, self).get_context_data(**kwargs)
# TODAY'S ENTRY
ctx['entry_qs'] = Entry.objects.filter(date=today_date)
# CURRENT SAVINGS TOTALS
ctx['savings_qs'] = Savings.objects.filter(id=1)
# MONTHLY TOTALS
# November
ctx['November16_qs'] = MonthYear.objects.filter(month='November')
# December
ctx['December16_qs'] = MonthYear.objects.filter(month='December')
# January
ctx['January17_qs'] = MonthYear.objects.filter(month='January')
# February
ctx['February17_qs'] = MonthYear.objects.filter(month='February')
# March
ctx['March17_qs'] …Run Code Online (Sandbox Code Playgroud) 我需要将数据框转换为字典,但无法从数据框获取所有值以出现在字典中。
数据框:
id| region | Num |
--|--------|-----|
2 | NYC |2344 |
3 | NYC |3243 |
4 | NYC |3253 |
5 | NYC |2345 |
6 | CHI |8756 |
7 | CHI |9786 |
8 | CHI |7674 |
9 | CHI |6678 |
10| ATL |1234 |
Run Code Online (Sandbox Code Playgroud)
码:
df.set_index('region').T.to_dict('list'):
我需要的是:
{'NYC: [2344, 3243, 3253, 2345 ], 'CHI': [8756, 9786, 7674, 6678], 'ATL': [1234] }
Run Code Online (Sandbox Code Playgroud)
但是我得到的是:
{'NYC: [2345 ], 'CHI': [6678], 'ATL': [1234] }
Run Code Online (Sandbox Code Playgroud)
我试过了: …
django ×2
dictionary ×1
django-urls ×1
django-views ×1
next.js ×1
pandas ×1
python ×1
python-3.x ×1
reactjs ×1