Replies: 8 comments 14 replies
-
Do you have an @app.route for "/static/css/index.css" ? One way is to make a general rule: |
Beta Was this translation helpful? Give feedback.
-
Another example for processors with constrained ram... # check if a file o dir exist
def fileOrDirExists(filename):
try:
os.stat(filename)
return True
except OSError:
return False
# server Routings
@app.route('/')
async def index(request):
#print(request.path)
return redirect('/main.html')
# all other files
@app.route('<path:path>')
async def sendPageOrFile(request, path):
# if user is logged in, restore timeout
if brd.currentUser['level']> -1:
brd.conn['lastServerLogin']=time.ticks_ms()
path=request.path
print('Requested: ' + path)
if '..' in path:
# directory traversal is not allowed
return 'Not found', 404
if '.html' in path :
# depends on...:
if brd.currentUser['level']<0:
if 'about.html' in path:
pass # -> open about without authentication
elif 'main.html' in path and brd.Setts['useAuth']==0:
pass # open main without authentication
else:
path = '/login.html' # login required
# second pass:
if dev.devStatus['error'] or dev.devStatus['warning']:
path = '/diagnostic.html' # login required
if fileOrDirExists('/static/html/' + path):
# generate and send page in chuck for low ram capability processors
async def generatePage(Path):
with open('/static/html' + path) as f:
for line in f:
if '$' in line:
line=fileManipulation(line,path)
yield(line)
return generatePage(path)
else:
return 'Not found', 404
elif '.css' in path:
return send_file(path)
elif '.js' in path:
return send_file(path, max_age=86400) # in seconds
elif '.ico' in path:
# fix for favicon
path='static/html/' + path
return send_file(path)
elif fileOrDirExists(path):
# other files
return send_file(path)
else:
return 'Not found', 404` |
Beta Was this translation helpful? Give feedback.
-
I am surprised by yours codes. I'm trying to reproduce the project described here, https://www.donskytech.com/building-a-micropython-wifi-robot-car/, and there is no mention of these static routes. |
Beta Was this translation helpful? Give feedback.
-
Hi,
|
Beta Was this translation helpful? Give feedback.
-
Hello, I tried to reproduce with the above but went into troubles. I added "Not found x" with a number to be sure where it exits. Seems it cannot find the files, while when I do it "by hand" with fileOrDirExists it works for all like a charm. Surely I missed something big but I am lost, if someone has a hint...? Thanks! David Here is what I used: from microdot import Microdot, Response, redirect, send_file #check if a file o dir exist class WebServer:
|
Beta Was this translation helpful? Give feedback.
-
Hello, Still a stupid question... Now have SSE working just had to copy full microdot as a folder... Rhaaa I will post my full test setup in case someone wants a full working stuff with multiple tasts, etc... |
Beta Was this translation helpful? Give feedback.
-
Never did this have to try out how to...
Ir. David Baldwin
B4E SRL - Administrateur
40, Rue de l'Etang
B-1410 Waterloo
Belgium
Mob: +32 477 56 29 78 <tel://+32 477 56 29 78>
Mail: ***@***.*** ***@***.***>
VAT : BE0635.630.310
Please consider our environment before printing this e-mail
Disclaimer:
This message and any attachments thereto are confidential. They may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. E-mail transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore is in no way liable for any errors or omissions in the content of this message, which may arise as a result of e-mail transmission. If verification is required, please request a hard copy.
Cet email, ainsi que ses annexes, est confidentiel. Il contient des informations particulières destinées à l'usage exclusif de celui à qui il est adressé. Si ce message est reçu par quelqu'un d'autre que son destinataire, merci de le retourner simplement en y répondant et ensuite de le supprimer de votre ordinateur. Si vous n'êtes la personne à qui ce message est destiné, vous ne pouvez en faire de copie, le faire circuler ou en divulguer l'existence à qui que ce soit. Si le présent message est incomplet ou incorrect, merci de le retourner à son expéditeur.
… Le 6 mars 2025 à 13:15, PatLub85 ***@***.***> a écrit :
Be careful, microdot is a rather large file. I transformed it into mpy to save space
—
Reply to this email directly, view it on GitHub <#13430 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AQGQ4IO4LXDTNJT4NEL6TFD2TA36XAVCNFSM6AAAAABYJ7X4ZWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENBRGM2TAMQ>.
You are receiving this because you commented.
|
Beta Was this translation helpful? Give feedback.
-
I meant mpy
Ir. David Baldwin
B4E SRL - Administrateur
40, Rue de l'Etang
B-1410 Waterloo
Belgium
Mob: +32 477 56 29 78 <tel://+32 477 56 29 78>
Mail: ***@***.*** ***@***.***>
VAT : BE0635.630.310
Please consider our environment before printing this e-mail
Disclaimer:
This message and any attachments thereto are confidential. They may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. E-mail transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore is in no way liable for any errors or omissions in the content of this message, which may arise as a result of e-mail transmission. If verification is required, please request a hard copy.
Cet email, ainsi que ses annexes, est confidentiel. Il contient des informations particulières destinées à l'usage exclusif de celui à qui il est adressé. Si ce message est reçu par quelqu'un d'autre que son destinataire, merci de le retourner simplement en y répondant et ensuite de le supprimer de votre ordinateur. Si vous n'êtes la personne à qui ce message est destiné, vous ne pouvez en faire de copie, le faire circuler ou en divulguer l'existence à qui que ce soit. Si le présent message est incomplet ou incorrect, merci de le retourner à son expéditeur.
… Le 6 mars 2025 à 17:38, PatLub85 ***@***.***> a écrit :
???
—
Reply to this email directly, view it on GitHub <#13430 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AQGQ4IKLN7V6ZS6C2WE6LH32TB2ZDAVCNFSM6AAAAABYJ7X4ZWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENBRGYZTQNA>.
You are receiving this because you commented.
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I love the simplicity of using microdot, however I can't link a CSS file to the HTML file.
In my ESP32 and Micropython, I have a /static/css directory and in my index.html in the directory /templates:
<link rel="stylesheet" href="http://clevelandohioweatherforecast.com//pFad.php?u=http://github.com/static/css/index.css" />
In my micropython file I have :
The HTML page displays correctly on my iPhone, but the CSS does not.
If I insert the CSS file directly into the HTML page with style tags, it works fine.
Where is my mistake?
Thank you for your help
Beta Was this translation helpful? Give feedback.
All reactions