-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I load .pyhtml templates? #22
Comments
Hello @William04A, |
I didn't realize the www folder... of course! But, I put two files in that folder: 192.168.4.1/test.html - Returns 200 So I think that the path is no longer the issue. |
Hello, |
I am using your server for a product and cannot, therefore, disclose any code. |
Ok, I understand and I thank you for that. |
I've been getting some similar (but different) difficulties while trying to use pyhtml templates. When Using a pyhtml file in Here's my code (/www/index.pyhtml exists on the device): from MicroWebSrv2 import *
mws2 = MicroWebSrv2()
mws2.SetEmbeddedConfig()
pyhtmlTemplateMod = MicroWebSrv2.LoadModule('PyhtmlTemplate')
pyhtmlTemplateMod.ShowDebug = True
mws2.RootPath = "www"
mws2.NotFoundURL = "index.pyhtml"
mws2.StartManaged() Here's the results of requests: 192.168.4.1/ -> 403 Forbidden If I try to use from MicroWebSrv2 import *
mws2 = MicroWebSrv2()
mws2.SetEmbeddedConfig()
pyhtmlTemplateMod = MicroWebSrv2.LoadModule('PyhtmlTemplate')
pyhtmlTemplateMod.ShowDebug = True
mws2.RootPath = "www"
mws2.AddDefaultPage('index.pyhtml')
mws2.StartManaged() 192.168.4.1/ -> 403 Forbidden If I use an html file (test.html so as to not be caught by default configs) instead of a pyhtml file, then both 192.168.4.1/ -> 200 OK |
Hello @echolocation,
|
That explains a lot, thank you!
…On Wed., Jan. 8, 2020, 7:34 p.m. J-Christophe Bos, ***@***.***> wrote:
Hello @echolocation <https://github.com/echolocation>,
Ok your results are normal because modules (like pyhtml) are not called
for a default page :
- RootPath is the physical root path, so 192.168.4.1/www doesn't
exists and is redirected if NotFoundURL is present.
- 192.168.4.1/ is the root directory and 403 is returned if no html
default page is present.
If you really want that '/' processes a .pythml file, you must to
handle '/' route and return a redirect to the .pythml file yourself.
In effect, modules are processed before http routes and are not called
for a specific file extension but when the request starts.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22?email_source=notifications&email_token=ABWJIDBVGMAXICCR2LPK2CDQ4ZWJLA5CNFSM4KB4I7ZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIOPYVI#issuecomment-572324949>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWJIDAFE374QSW57ALQJIDQ4ZWJLANCNFSM4KB4I7ZA>
.
|
Absolutely, I am doing that and getting back ASAP. |
Running the demo and visiting /test.pyhtml gives me a 307 Temporary Redirect to the index page. I assume that is not expected...?
The example seems to 307 everything for me... |
Ok I see and I don't understand why the first
There seems to be a problem reading the file size in the returned tuple. |
I could not get to pdf.png for some reason, but it is under www/pdf.png on my device. I am using a PyCom WiPy. If I can help out with anything, tell me and I'll provide what you need. |
Hmm, it seem that you have a problem with files... |
I am looking for some help trying to get the .pyhtml templates to load. I have read over everything I could find with no luck. With this configuration, it will 'download' the file to my machine '[200] OK' but won't render. What am I doing wrong? I am trying to get the /testpy.pyhtml to load: ######################################## @webroute(GET, '/testpy') mws2 = MicroWebSrv2() Main program loop until keyboard interrupt,try : |
Ok I got it figured out for anyone else that might come across this problem... @webroute(GET, '/testpy') mws2 = MicroWebSrv2() try : |
Hi @interconnectix, indeed, |
Hi @jczic, what would you recommend then for code to call the function directly? I am currently using a redirect using routes. |
And using the routes is the normal and easiest way :) |
This may sound like a silly question - and it probably is, because I should have been able to get this to work by now.
I want/need to include a .pyhtml file in the application I am making.
I looked in the source code, and the PyHTML extension should automatically send and render the template when I go to a page with the name of my PyHTML and .pyhtml in the end, correct?
So, if I have a file named "page.pyhtml", I should simply be able to visit /page.pyhtml?
Because, that gives me a 404 error.
I have initialized the PyHTML addon and I have enabled debugging, but I did not get any output from the debugger.
The text was updated successfully, but these errors were encountered: