Dynamic Web album python write simple folder picture browsing tool,

Source: Internet
Author: User
Tags shuffle

Dynamic Web album python write simple folder picture browsing tool,

I don't know if you have such an experience. If you view a gif image on a windows computer, IE is opened by default. What other inquiry items are displayed, Which is troublesome. To solve this problem, I wrote a simple image browsing tool in the folder.


Take a folder on an edisk as an example.


Implementation

Business Code

# Coding: utf-8import sysreload (sys) sys. setdefaultencoding ('utf8 ') # _ author _ = 'Guo pu' # _ date _ = '2017/5' # _ Desc _ = Automatic Generation of webpage album import OS # Haha, there was originally a walk Method in the standard library. In this way, obtain the image file in a folder. def getFiles (filepath): files = [] if OS. path. isdir (filepath): for file in OS. listdir (filepath): if OS. path. isdir (file): getFiles (file) elif file.endswith('.jpg ') or file.endswith('.png') or file.endswith('.gif '): files. append (filepath + str (file) elif OS. path. isfile (filepath): files. append (filepath) return files # All .jpg files under the specified directory. png. save the file ending with gif and complete the path to the list to output def recourse (filepat H): files = [] for fpathe, dirs, fs in OS. walk (filepath): for f in fs: if f.endswith('.jpg ') or f.endswith('.png') or f.endswith('.gif '): files. append (OS. path. join (fpathe, f) return files # generate the webpage source code file and specify def generate (files, shuffle = False ): template_start = ''' 

Summary
• Disadvantages:
The disadvantages of the scheme are obvious. It is not good enough to support Chinese characters because the large image is displayed in the form of hyperlinks, so garbled characters may occur.
Then there are advantages:
The advantage is not obvious, because if a folder contains many subfolders or images, it will be slow.

• Let's talk about the improvements.
◦ Introduces JQuery and adds double-click events to remove unwanted images.

◦ Uses multi-threaded code to accelerate the generation of web pages

Finally, I would like to say that although this is an entertaining little thing, it will certainly be helpful for us to make full use of our imagination and constantly improve our development.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.