omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to open HTML Files in a Webbrowser

    Pythonista
    7
    17
    16378
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • myko
      myko last edited by

      I am a complete beginner. I try to do some examples from a python learning book. One example explains how to build a webapp. The webbapp should search for letters in words, which I should be able to fill in the html form (this example also uses Flask). I wonder if i can do it with pythonista. I created in pythonista a script, html pages and css files. The first problem is that i don't know how to open my html files from pythonista in a webbrowser. I have found out how to open an url or quicklook. Is it any way to open html files in a browser? Thank you!

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp last edited by cvp

        file_path = urlparse.urljoin('file://', os.path.abspath(file_path))
        w = ui.WebView()
        w.load_url(file_path)
        
        myko 1 Reply Last reply Reply Quote 0
        • myko
          myko @cvp last edited by myko

          @cvp Thank you! Where should i enter the name of my file? The name is "base.html". I tried this option with a console, but it didnt function.

          file_path = urlparse.urljoin('file://', os.path.abspath('base.html'))
          w = ui.WebView()
          w.load_url(file_path)

          Error message:

          File "<string>", line 1
          file_path = urlparse.urljoin('file://', os.path.abspath('base.html'))

          SyntaxError: multiple statements found while compiling a single statement

          1 Reply Last reply Reply Quote 0
          • cvp
            cvp last edited by cvp

            Try this, it works (with base.html in the same folder as your script)

            import ui,os
            from urllib.parse import urljoin
            file_path = 'base.html'
            file_path = urljoin('file://', os.path.abspath(file_path))
            w = ui.WebView()
            w.load_url(file_path)
            w.present()
            
            1 Reply Last reply Reply Quote 1
            • myko
              myko last edited by

              Thank you! It works.

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by omz

                It's actually not necessary to construct a file:// URL yourself, you can simply pass an absolute file path (i.e. os.path.abspath('base.html')) to load_url, and it'll be converted to a URL internally.

                Naïvely concatenating 'file://' + path can lead to problems when your path contains spaces etc.

                sallyno80 1 Reply Last reply Reply Quote 2
                • cvp
                  cvp last edited by

                  @omz I learn every day...
                  One more time, Thanks for your marvelous application, it has changed my life, really.
                  I'm retired, I was reading a lot, and now, I almost only use your app.
                  That's why all my files are now on my iPad, and my Mac is only used as a backup

                  1 Reply Last reply Reply Quote 1
                  • naturale
                    naturale last edited by naturale

                    This script might help: github

                    1 Reply Last reply Reply Quote 0
                    • sallyno80
                      sallyno80 @omz last edited by

                      @omz
                      Hello you can u send my a video tutorial how to open pythonista file in google chrome I am a beginner in programming
                      Thank you

                      1 Reply Last reply Reply Quote 0
                      • dolanskurd
                        dolanskurd last edited by

                        It works perfect. Thank you.

                        Is there any way to use external CSS instead internal styles (in the same folder)?!!

                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @dolanskurd last edited by cvp

                          @dolanskurd This works but I'm not sure that I correctly understand your question, my fault::
                          base.html

                          <!doctype html>
                          <html>
                          	<head>
                          		<meta charset="utf-8">
                          		<title>Title</title>
                          		<link rel="stylesheet" type="text/css" href="mystyle.css">
                          	</head>
                          	
                          	<body>
                          	
                          	<h1>Hello</h1>
                          	
                          	</body>
                          	
                          </html>
                          

                          mystyle.css

                          body {
                              background-color: lightblue;
                          }
                          
                          h1 {
                              color: navy;
                              margin-left: 20px;
                          }
                          
                          1 Reply Last reply Reply Quote 1
                          • dolanskurd
                            dolanskurd last edited by dolanskurd

                            Thanks for prompt replying.
                            Yes exactly, I meant as the normal way which we are working with HTML & CSS next to each-other and link the CSS file in the HTML file. I have tested it but couldn’t success to link the CSS file to the HTML.

                            As folllows:

                            <head>
                            <link rel="stylesheet" type="text/css" href="theme.css">
                            </head>

                            NOT using styles inside the HTML file.

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @dolanskurd last edited by cvp

                              @dolanskurd I don't understand what doesn't work for you.
                              My little script + Base.html + mystyle.css in the same folder do work.

                              shinowtf 1 Reply Last reply Reply Quote 2
                              • dolanskurd
                                dolanskurd last edited by

                                Yesss, I tried it and it works perfect! Thank you.

                                1 Reply Last reply Reply Quote 0
                                • shinowtf
                                  shinowtf @cvp last edited by

                                  @cvp hi dear cvp
                                  Hi i did run the code u send but the output of my html project is not fullsize..which mean all the margin is ruin due to small webview only?any solution to enlarge the webview for whole screen?

                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @shinowtf last edited by

                                    @shinowtf try

                                    w.present('fullscreen')
                                    
                                    shinowtf 1 Reply Last reply Reply Quote 1
                                    • shinowtf
                                      shinowtf @cvp last edited by

                                      @cvp tqqqqqqqq!!!

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post
                                      Powered by NodeBB Forums | Contributors