[Django]-How do I rename a Django project in PyCharm?

48đź‘Ť

âś…

The built-in solution for re-naming Django projects in PyCharm has worked for me in the past on small projects, although I haven’t tried it on a large project yet. To use it, select the project folder from the file-tree (by default on the left hand side of the screen), then press shift-F6 to bring up the rename dialogue. You can enter in your new name here and preview the changes, which can help prevent surprises. If you’re happy with the preview, click on the “Do Refactor” button at the bottom of the window.

This is also a useful way to rename Django apps.

You can access the same functionality through right-clicking on the folder/item and hovering over the Refactor sub-menu. Or pressing ctrl+shift+a and searching for rename.

👤svass

12đź‘Ť

I’m using Windows, but it’s probably the same for other operating systems.

  1. Close PyCharm, open the directory in Windows Explorer (or your favorite file manager).
  2. Rename the project directory.
  3. Rename the subdirectory of the same name that is inside your project directory.
  4. Open the .idea directory (in the project folder), rename the .iml file.
  5. Also in the .idea directory, open the .name file in a text editor and change the name in there.
  6. Open the project in PyCharm again.
  7. In the settings.py file, you’ll need to update the path specified in TEMPLATE_DIRS.

You may also want to update your Run/Debug configurations (Alt+Shift+F10).

You’ll need to replace some other occurrences of your old project name. In PyCharm, Ctrl+Shift+F will allow you to search the contents of all your files to find these occurrences.

👤northben

10đź‘Ť

Maybe: right-click on root folder in “Project” window, choose Refactoring -> Rename and choose “Rename Project”

👤Evgenii

3đź‘Ť

svass’s answer worked for me, except that I also had to manually change instances of my old project name in files located inside the .idea directory of my project.

If you cd into your project directory and grep for your old project name

grep -rli oldprojectname ./.idea

That returned the following list for me, then I manually modified each file.

./.idea/modules.xml
./.idea/workspace.xml
./.idea/dataSources.xml
./.idea/oldprojectname.iml <-- this will need to be renamed to new project name, and it's contents modified
./.idea/dataSources.ids
./.idea/.name
./.idea/misc.xml
👤pymarco

Leave a comment