28132

Change skeleton templates in PyCharm

Question:

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.

Recommend

  • invalid command name “Queue/LTEQueue”
  • Pycharm html indentation
  • cython compiles but no pyd files are generated
  • how to restrict price range in google shopping API
  • Simple validation with SQLAlchemy
  • ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context : while initializing Chrome bro
  • Create a JSON file from a Flask view to be used with D3
  • Is it always a good idea to import very specifically in Python?
  • Flask-Restful error: “as_view” method not inherited
  • How to record a JNLP/ Java Web Start application with JMeter
  • Django AWS S3 Invalid certificate when using bucket name “.”
  • Retrieve Facebook Account Information in ios 6
  • How to make nicEditor snaplet? (Several questions)
  • integrate POCO library in android ndk
  • How to save dynamically created textboxes and their values
  • Classic ASP URL Rewriting
  • init_seg and warning C4073 from library code?
  • MAVEN : Run Multiple Maven Project using Maven Test
  • TFS - how do I sum child task hours to parent
  • .NET video play library which allows to change the playback rate?
  • jquery validation - waiting for remote check to complete
  • “mvn clean generate-source” could not resolve dependencies
  • In Java, how can I construct a File from a resource?
  • Android Studio Can't Find tools.jar
  • Overlapping controls in Windows XP
  • SharedPreferences or SQLite Database?
  • Alternative to overridePendingTransition() - Android
  • Eloquent update method change created_at timestamp
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • How to get Eclipse Oxygen to run on Java 9
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • jQuery tmpl and DataLink beta
  • XCode can't find symbols for a specific iOS library/framework project
  • How do I rollback to a specific git commit
  • Unanticipated behavior
  • Is there a mandatory requirement to switch app.yaml?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Busy indicator not showing up in wpf window [duplicate]