问题描述
我去过这条路线http://127.0.0.1:8000/static/corefiles/chatbot-data.xlsx
,但遇到Page not found (404)
错误...
我将它们添加到了URL中:
+ static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
文件目录为/rootproject/core/static/corefiles/testexel.xlsx
我的settings.py
:
STATIC_URL ='/ static /'
STATICFILES_DIRS =( normpath(join(BASE_DIR,'static')), normpath(join(BASE_DIR,'upload')),)
STATIC_ROOT = normpath(join(BASE_DIR,'assets'))
解决方法
要在项目中使用静态文件,如果需要查看指定URL处的文档,则需要在设置中指定媒体URL和媒体根:
+ static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
还将这些内容添加到网址中
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
import mysql.connector
import re
from kivy.lang import Builder
class OperatorWindow(BoxLayout):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.mydb = mysql.connector.connect(
host='localhost',user='root',passwd='Livingstone2#',database='pos'
)
self.mycursor = self.mydb.cursor()
self.stocks = ''
self.cart = []
self.qty = []
self.total = 0.00
def logout(self):
self.parent.parent.current = 'scrn_si'
def update_purchases(self):
pcode = self.ids.code_inp.text
products_container = self.ids.products
#target_code = self.mycursor.fetchall({'product_code': pcode})
target_code = self.stocks.find_one({'product_code': pcode})
if target_code == None:
pass
else:
details = BoxLayout(size_hint_y=None,height=30,pos_hint={'top':
1})
products_container.add_widget(details)
code = Label(text=pcode,size_hint_x=.2,color=(.06,.45,1))
name = Label(text=target_code['product_name'],size_hint_x=.3,1))
qty = Label(text='1',size_hint_x=.1,1))
disc = Label(text='0.00',1))
price = Label(text=target_code['product_price'],1))
total = Label(text='0.00',1))
details.add_widget(code)
details.add_widget(name)
details.add_widget(qty)
details.add_widget(disc)
details.add_widget(price)
details.add_widget(total)
#Update Preview
pname = name.text
pprice = float(price.text)
pqty = str(1)
self.total += pprice
purchase_total = '`\n\nTotal\t\t\t\t\t\t\t\t'+str(self.total)
self.ids.cur_product.text = pname
self.ids.cur_price.text = str(pprice)
preview = self.ids.receipt_preview
prev_text = preview.text
_prev = prev_text.find('`')
if _prev >0:
prev_text = prev_text[:_prev]
ptarget = -1
for i,c in enumerate(self.cart):
if c == pcode:
ptarget = i
if ptarget >= 0:
pqty = self.qty[ptarget]+1
self.qty[ptarget] = pqty
expr = '%s\t\tx\d\t' % (pname)
rexpr = pname + '\t\tx' + str(pqty)+'\t'
nu_text = re.sub(expr,rexpr,prev_text)
preview.text = nu_text + purchase_total
else:
self.cart.append(pcode)
self.qty.append(1)
nu_preview = '\n'.join([prev_text,pname + '\t\tx' + pqty +
'\t\t' + str(pprice),purchase_total])
preview.text = nu_preview
self.ids.disc_input.text = '0.00'
self.ids.disc_perc_input.text = '0.00'
self.ids.qty_input.text = str(pqty)
self.ids.price_input.text = str(pprice)
self.ids.vat_input.text = '15%'
self.ids.total_input.text = str(pprice)