Python Flask serving static files from root static folder rather than blueprint's static folder -


मेरे पास एक ब्लूप्रिंट परिभाषित है:

  auth_login = blueprint ('auth_login', __name__ , Template_folder = 'templates', static_folder = 'static', static_url_path = '/ static')   

मैं इसे इस रूप में पंजीकृत कर रहा हूं:

  app.register_blueprint (Auth_login, url_prefix = '/ user')   

मेरे पास एक मार्ग है:

  @ auth_login.route ('/ & lt; उपयोगकर्ता नाम & gt; /') डीफ प्रोफाइल (यूज़रनेम): रिटर्न रैडर_टामप्लेट ('प्रोफाइल / यूजरओएम', यूज़रनेम = यूज़रनेम)   

इस सेटअप के साथ, / यूज़र / एंड पॉइंट स्थिर फाइल को लोड करने के लिए कभी भी प्रबंधित नहीं करता I प्राप्त करें,

"GET /user//static/css/lib/bootstrap.min.css HTTP / 1.1" 404 - "प्राप्त / उपयोगकर्ता // स्थैतिक / CSS / lib / font-awesome / css / font-awesome.min.css एचटीटीपी / 1.1 "404 -

मैं वास्तव में क्या चाहता हूं रूट अनुप्रयोग के स्थैतिक फ़ोल्डर में देखना और खाका नहीं है, इसलिए मैं इसे अनुरोध करना चाहता हूं

"/static/css/lib/bootstrap.min.css HTTP / 1.1" प्राप्त करें - 200 -

क्या यह इस वी को कॉन्फ़िगर करना संभव है Ia static_folder या static_url_path ताकि रूट रूट पर स्थैतिक फाइलों के लिए दिखेगा और उस खासतौर पर नहीं कि ब्लूप्रिंट कहाँ स्थित है?

डिफ़ॉल्ट रूप से, फ्लास्क / static यूआरएल को {application_root} / static से बाहर फाइलों को सेवा देने के लिए सेट करता है - आप overwriting आपके ब्लूप्रिंट के कोड के साथ यह डिफ़ॉल्ट। (यूआरएल अब भी / static है लेकिन फ़ोल्डर {application_root} / path / to / blueprint / static है, जो चीजों की आवाज़ से, जो आप चाहते हैं वह नहीं है )।

बस हटाएं को static_folder और static_url तर्क अपने ब्लूप्रिंट आरंभीकरण और URL को ठीक से काम करना चाहिए (यह मानते हुए कि आपके पास अपने {application_root} / static फ़ोल्डर में उचित सीएसएस है।)

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -