is there a way I can change the main skeleton templates in PyCharm?
Whenever I start a new (for example) Flask project I have to alter the skeleton to fit my needs. It would be great if I could say PyCharm to start a new project with a static folder and a template folder, a specific base.html, database template and so on...
Is this somehow possible?
Adding a new skeleton or alter an existing one would be what I need. Any ideas?Answer1:
This kind of customization is only possible by writing a plugin. The only thing that can be changed without writing a plugin is the main.py that PyCharm generates: it can be changed under Settings | File Templates | Flask Main.Answer2:
I just took a look at the plugin directory, and I think it's probably possible right now, although not for the faint of heart.
Look in PyCharm/plugins/pycharm-flask/ and it looks like there's a jar with the template files in it:
bloop:s r$ jar xvf resources_en.jar created: META-INF/ extracted: META-INF/MANIFEST.MF created: fileTemplates/ created: fileTemplates/internal/ extracted: fileTemplates/internal/Flask Main.py.ft bloop:s r$ cat fileTemplates/internal/Flask\ Main.py.ft from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
I replaced the Flask\ Main.py.ft file and it worked for me. Here's how I did it:
I closed PyCharm entirely, no open windows, no running processes, then in a shell:
$ cd /Applications/PyCharm.app/plugins/pycharm-flask/lib $ cp resources_en.jar backup $ mkdir -p fileTemplates/internal $ cat >fileTemplates/internal/Flask\ Main.py.ft from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello Custom World!' if __name__ == '__main__': app.run() ^D $ jar -uf resources_en.jar fileTemplates/internal/Flask\ Main.py.ft
Then started up PyCharm and started a new project, specifying Flask as the type:
And when it opened up:
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/DOmba.png" data-original="https://i.stack.imgur.com/DOmba.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
For what it's worth, this method is an extremely hacky means to an end. If you just want to change the default main, this works in a pinch if you're not picky.
If you want to do it the <em>pro</em> way, you can get the source code for the Flask plugin from the <a href="https://github.com/JetBrains/intellij-plugins/tree/master/pycharm-flask" rel="nofollow">Intellij Plugin GIT</a>. If you follow the <a href="http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment" rel="nofollow">instructions on Jetbrain's webpage</a> they explain how to download the community version of Intellij and how to build and package plugins.