亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python3.7加django2.1,http://127.0.0.1:8000/blog/edit/action/無法跳轉到首頁

def?edit_page(request):
????return?render(request,'blog/edit_page.html')

def?edit_action(request):
????title?=?request.POST.get('title','TITLE')
????content?=?request.POST.get('content','CONTENT')
????#?title?=?request.POST['title']
????#?content?=?request.POST['content']
????models.Article.objects.create(title=title,content=content)
????#?return?HttpResponseRedirect(reversed('/blog/index/'))
????articles?=?models.Article.objects.all()
????return?render(request,?'blog/index.html',?{'articles':?articles})


<!DOCTYPE?html>
<html>
<head>
????<meta?charset="UTF-8">
????<title>Edit?Page</title>
</head>
<body>
<form?action="/blog/edit/action/"?method="post">
?{%?csrf_token?%}
????<label>Title
????????<input?type="text"?name="Title">
????</label>
????<br/>
????<label>Content
????????<input?type="text"?name="Content">
????</label>
????<br/>
????<input?type="submit"?value="Submit">
</form>
</body>
</html>
urlpatterns?=?[
????re_path('index/',?views.index),
????re_path('article/(?P<article_id>[0-9]+)/',?views.article_page,name?=?'article_page'),
????#?re_path('article/(?P<article_id>[0-9]+)/',?views.article_page),
????re_path('edit/',views.edit_page,name?=?'edit_page'),
????re_path('edit/action/',views.edit_action,?name?=?'edit_action'),
]



<!DOCTYPE?html>
<html>
<head>
????<meta?charset="UTF-8">
????<title>Title</title>
</head>
<body>
{#<h1>{{?article.title?}}</h1>#}
{#<h3>{{?article.content?}}</h3>#}
<h1>
????<a?href="">新文章</a>
</h1>
{%??for?article?in?articles?%}
????<a?href="{%url?'blog:article_page'?article.id?%}">{{?article.title?}}</a>
{#????<a?href="/blog/article/{{?article.id?}}">{{?article.title?}}</a>#}
?<br/>
{%?endfor?%}
</body>
</html>


https://img1.sycdn.imooc.com//5b90dd590001c85107480291.jpg

正在回答

4 回答

?File "D:\Program Files\Anaconda3\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func

? ? response = view_func(request, *args, **kwargs)

? File "E:\workspaces\MxOnline\extra_apps\xadmin\views\website.py", line 66, in get

? ? return login(request, **defaults)

TypeError: login() got an unexpected keyword argument 'extra_context'

[21/May/2019 15:44:13] "GET /xadmin/ HTTP/1.1" 500 89464

和你一樣的問題 請問你解決了嗎? 怎么處理

0 回復 有任何疑惑可以回復我~

求問題xadmin后有遇到TypeError: login() got an unexpected keyword argument 'extra_context'這個問題嗎,版本和您的一樣

0 回復 有任何疑惑可以回復我~
edit_action?的路由應該這么寫:
path('index/',?views.edit_action,?name='edit_action'),


0 回復 有任何疑惑可以回復我~
#1

學一點忘一點

我試了你的,雖然數據提交后可以跳轉到首頁,但是數據根本沒有真正的提交到數據庫中,所以首頁也沒有數據,只是跳轉到首頁去了,還是不行,按理來說寫入數據后,最后應該跳轉到首頁去的,我去看看view.py中的邏輯,看看能否遷移到index去
2019-01-09 回復 有任何疑惑可以回復我~
應該改成re_path('edit_action/',views.edit_action,?name?=?'edit_action'),
還有<label>Title
????????<input?type="text"?name="Title">
????</label>
????<br/>
????<label>Content
????????<input?type="text"?name="Content">
????????應該是<input?type="text"?name="title">
????</label>
????<br/>
????<label>Content
????????<input?type="text"?name="content">
????????這樣就可以運行了


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
django入門與實踐
  • 參與學習       65128    人
  • 解答問題       898    個

手把手帶你進入Django開發的大門,充分領略Django的魅力

進入課程

python3.7加django2.1,http://127.0.0.1:8000/blog/edit/action/無法跳轉到首頁

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號