Django做了一个生成文章的静态函数,如何让链接只能在登录的状态下才能访问?并且在admin后台增加一个对应的按钮,点击这个按钮就直接访问了这个函数对应链接,从而实现后台一键生成首页内容?
生成文章的函数如下pl_index.py:
```python
from .models import detail,indexct,artlist,specialdetail
from django.shortcuts import HttpResponse
from django.views import View
from django.db.models import Max
# from django.contrib.auth.decorators import login_required
def indextop(inxid,fg):
……
def indexlm(inxid,lmid):
……
def indexwz(atype,fg,shu,ctid):
……
class indexCt(View):
def get(self, request):
try:
indextop(1, "f")
indextop(2, "h")
indexlm(3,1)
indexlm(4,2)
indexlm(5,3)
indexlm(6,4)
indexlm(7,5)
indexlm(8,6)
indexlm(9,7)
indexlm(10,8)
indexlm(11,9)
indexlm(12,10)
indexwz("ask", "c", 10, 13)
indexwz("art", "o", 20, 14)
except Exception as e:
return HttpResponse ("更新失败,原因:!"+ str(e))
else:
return HttpResponse ("首页更新成功!")
if __name__=="__main__":
get()
urls.py中
urlpatterns = [
……
url(r'^index/$',pl_index.indexCt.as_view(),name='indexCt'),
……
]
```