我不知道如何在cherrypy中进行路由以及如何在index.py
的conf中定义css和js文件
我有一个结构:
index.py
|
-views
|
-home
|
-index.html
-login.html
-public
|
-css
bootstrap.css
...
-js
-images
当我在站点中以Cherrypy
启动index.html
服务器时,在404
文件中有css
,并且当我单击带有href
到{{ 1}}我不能去那里,因为我看到login.html
。请帮忙,因为我是`Cherrypy的新手。
404
import cherrypy
import webbrowser
import os, os.path
VIEWS_DIR = os.path.join(os.path.abspath("."), u"VIEWS")
CSS_DIR = os.path.join(os.path.abspath("."), u"CSS")
class Main(object):
@cherrypy.expose()
def index(self):
return open('views/home/index.html', 'rb').read().decode('utf-8')
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd()),
},
'/static/views/home':
{'tools.staticdir.on': True,
'tools.staticdir.dir': VIEWS_DIR,
},
'/bootstrap.css':
{ 'tools.staticfile.on':True,
'tools.staticfile.filename': os.path.abspath ("./public/css/bootstrap.css"),
},
}
def open_page():
webbrowser.open("http://127.0.1.1:8080/")
cherrypy.engine.subscribe('start', open_page)
cherrypy.tree.mount(Main(), '/', conf)
cherrypy.engine.start()
在404 error
文件中,当我单击指向站点css
中的href
链接时
答案 0 :(得分:0)
要按预期工作,您的href应以/ static / views / home或/ static / public / css加上目标文件名开头。根据您的结构,您应该像我的示例一样映射两条静态路线
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd()),
},
'/static/views/home': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './views/home',
},
'/static/public/css': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './public/css',
}
}
,随后您的html应该看起来像
<!DOCTYPE html>
<html>
<head>
<link href="/static/public/css/style.css" rel="stylesheet">
</head>
<body>
<p>
<a href="/static/views/home/login.html">Login</a>
</p>
</body>
</html>
答案 1 :(得分:0)
@prodops我用另一种方式解决了它。 在index.py
中When I set @doc_id VARCHAR(100) = NULL and @line_id VARCHAR(100) = NULL
以及在我拥有的index.html网站中
ALTER PROCEDURE [dbo].[TEST]
@companycode VARCHAR(100) = NULL,
@division VARCHAR(100) = NULL,
@doc_id BIGINT = NULL,
--@doc_id VARCHAR(100) = NULL,
@doc_type_id VARCHAR(100) = NULL,
@fileid VARCHAR(100) = NULL,
@line_id INT = NULL,
--@line_id VARCHAR(100) = NULL,
@m3UpdateStatus VARCHAR(100) = NULL,
@m3VoucherNo VARCHAR(100) = NULL,
@posted_by VARCHAR(100) = NULL,
@post_priority VARCHAR(100) = NULL,
@samsung_doc_no VARCHAR(100) = NULL,
@serp_doctype VARCHAR(100) = NULL,
@serp_status_id VARCHAR(100) = NULL,
@year VARCHAR(100) = NULL,
@period VARCHAR(100) = NULL,
@transactionType VARCHAR(100) = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
print 1
DECLARE db_cursor CURSOR FOR
SELECT [doc_id] --@doc_id
,[samsung_doc_no] --@samsung_doc_no
,[posted_by] --@posted_by
,[post_priority] --@post_priority
,[serp_status_id] --@serp_status_id
,[line_id] --@line_id
,[fileid] --@fileid
,[serp_doctype] --@serp_doctype
,[doc_type_id] --@doc_type_id
,[companycode] --@companycode
,[m3VoucherNo] --@m3VoucherNo
,[m3UpdateStatus] --@m3UpdateStatus
,[division] --@division
,[year] --@year
,[period] --@period
,[transactionType] --@transactionType
FROM [dbo].[post]
LEFT JOIN [dbo].[DM] ON [dbo].[DM].[BA] = [dbo].[post].[serp_doctype]
WHERE [dbo].[DM].[DT] = 'Y2' AND [dbo].[post].[serp_status_id] = 'TEST'
AND [dbo].[post].[serp_post_id] IN (120774,120773,120772,120771,120770)
print 2
Declare @now datetime = getdate();
OPEN db_cursor
print 3
FETCH NEXT FROM db_cursor INTO @companycode,@division,@doc_id,@doc_type_id,@fileid,@line_id,@m3UpdateStatus,@m3VoucherNo,@posted_by,@post_priority,@samsung_doc_no,@serp_doctype,@serp_status_id,@year,@period,@transactionType
print 4
WHILE @@FETCH_STATUS = 0
BEGIN
print 5
INSERT INTO [dbo].[post] (doc_id ,samsung_doc_no ,created_date ,process_type,posted_by,post_priority,posting_date,status_id,serp_status_id,line_id,fileid,serp_doctype,doc_type_id,companycode,m3VoucherNo,m3UpdateStatus,division,year,period,transactionType)
VALUES(@doc_id,@samsung_doc_no,@now,'CHECK_STATUS',@posted_by,@post_priority,@now,'O',@serp_status_id,@line_id,@fileid,@serp_doctype,@doc_type_id,@companycode,@m3VoucherNo,@m3UpdateStatus,@division,@year,@period,@transactionType)
FETCH NEXT FROM db_cursor INTO @companycode,@division,@doc_id,@doc_type_id,@fileid,@line_id,@m3UpdateStatus,@m3VoucherNo,@posted_by,@post_priority,@samsung_doc_no,@serp_doctype,@serp_status_id,@year,@period,@transactionType
END
print 6
CLOSE db_cursor
DEALLOCATE db_cursor
END