Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Creating a drag and drop system

I'm creating sort of a "local website" for organizations that need to spread digital resources in parts of the world where internet is either too unstable or doesn't exist at all. It all runs off of a usb drive pluged into a wireless router with modified firmware (very similar to a PirateBox, if you're familiar with that).

I need the users to be able to simply drag and drop files into specified folders and have them appear on the site. I was using PHP's GLOB to do this, but the software which runs all of this (which I did not create) seems pretty limited for what it allows PHP to do. Specifically, it won't allow GLOB to work.

Here's the code I originally intended on using, if that's any help:

<div>
    <?php
        $docs = glob("other_docs/*.{pdf,txt,doc,docx}", GLOB_BRACE);
        foreach ($docs as $doc) { ?>            
                <a href='<?php echo $doc; ?>' target='_blank' class='backing'>
                        <h3><?php echo substr($doc, 11); ?></h3>
                </a>            
    <?php       
        }
    ?>
</div>

So, basically, I need to do the same thing (allow users to drag and drop files into certain folders and have it appear on a certain web page), but with a different tool instead of PHP. I'm a new programmer so I'm not very familiar with what tools are available that will achieve this. Is this something Python could easily accomplish? Or is there some other way to do this that I may not have thought about yet?

Any advice is appreciated!

1 Answer

Flask is pretty simple as far as frameworks go, and although I haven't used it, Flask-flatPages and/or Frozen-Flask might do what you need. https://pythonhosted.org/Flask-FlatPages/ https://pythonhosted.org/Frozen-Flask/

Here's an interesting article about hosting a static site with FlatPages and Frozen-Flask https://nicolas.perriault.net/code/2012/dead-easy-yet-powerful-static-website-generator-with-flask/