Live preview of Django templates
Enable the Django plugin
This functionality relies on the Django plugin, which is bundled and enabled in PyCharm by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press Ctrl+Alt+S to open settings and then select
.Open the Installed tab, find the Django plugin, and select the checkbox next to the plugin name.
PyCharm lets you preview Django templates while editing them. The preview is shown automatically when you open a template in the editor.
Preview a Django template
Open the template in the editor. If the template is associated with an URL pattern, the preview will be displayed automatically.
You can toggle the preview mode by using the selector in the top-right corner of the editor.
Select one of the following modes:
Editor - to show only the editor
Editor and Preview - to show the editor and the preview
Preview - to show only the preview
You can use the Go Forward and Go Back actions to navigate through recently previewed templates.
To reload the currently opened template preview, click Refresh.
Depending on the URLs defined in
urlpatterns
, you may need to specify URL parameters to preview the template.You can specify an arbitrary URL in the address bar. If it matches any URL pattern, the preview of the corresponding template will be shown.
When doing so, provide the URL without the
address:port
part (for example, do not includehttp://localhost:8000/
).A template may be associated with several URL patterns. To view the template as rendered for a specific URL, expand the address bar and select the desired pattern.
To open the JCEF DevTools dialog, click Open Developer Tools.
Split editor and preview horizontally
By default, the editor and the preview are split vertically (side by side), which is convenient for wide monitors. You can also split it horizontally, so that the preview is displayed in the lower part of the editor, which is more convenient for portrait displays.
In the top-right corner of the editor, click to open the Editor Preview pane.
Click to split the editor and the preview horizontally.