如何在PyCharm中重命名Django项目?

时间:2021-04-22 07:08:13

What do I need to do in order to rename my Django project in PyCharm? I am new to Django and PyCharm and would like to use a different name for my project.

为了在PyCharm中重命名我的Django项目,我需要做什么?我是Django和PyCharm新手,我想给我的项目取一个不同的名字。

4 个解决方案

#1


46  

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.

在PyCharm中重新命名Django项目的内置解决方案过去对我在小项目上起过作用,尽管我还没有在大项目上尝试过。要使用它,请从文件树中选择project文件夹(默认位于屏幕左边),然后按shift-F6打开rename对话框。您可以在这里输入您的新名称并预览更改,这将有助于防止出现意外。如果你对预览很满意,点击窗口底部的“Do Refactor”按钮。

This is also a useful way to rename Django apps.

这也是重命名Django应用程序的一种有用方法。

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.

您可以通过右键单击文件夹/项并将鼠标悬停在Refactor子菜单上来访问相同的功能。或者按ctrl+shift+a,搜索rename。

#2


12  

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

我使用的是Windows操作系统,但其他操作系统可能也是如此。

  1. Close PyCharm, open the directory in Windows Explorer (or your favorite file manager).
  2. 关闭PyCharm,在Windows资源管理器(或你最喜欢的文件管理器)中打开目录。
  3. Rename the project directory
  4. 重命名项目目录
  5. Rename the subdirectory of the same name that is inside your project directory
  6. 重命名项目目录中相同名称的子目录。
  7. Open the .idea directory (in the project folder), rename the .iml file
  8. 打开.idea目录(在项目文件夹中),重命名.iml文件
  9. Also in the .idea directory, open the .name file in a text editor and change the name in there
  10. 在.idea目录中,在文本编辑器中打开.name文件并在其中更改名称
  11. Open the project in PyCharm again.
  12. 在PyCharm再次打开项目。
  13. In the settings.py file, you'll need to update the path specified in TEMPLATE_DIRS
  14. 在设置。py文件,您需要更新TEMPLATE_DIRS中指定的路径。

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

您可能还想更新您的运行/调试配置(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.

您将需要替换一些旧项目名称的其他出现。在PyCharm中,Ctrl-Shift-F将允许你搜索所有文件的内容来找到这些东西。

#3


10  

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

也许:在“项目”窗口中右键单击根文件夹,选择重构->重命名,选择“重命名项目”

#4


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.

svass的回答对我起了作用,除了我必须在项目的.idea目录内的文件中手动更改旧项目名的实例。

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

如果您将cd存储到项目目录中,并使用grep获取旧的项目名称

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

#1


46  

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.

在PyCharm中重新命名Django项目的内置解决方案过去对我在小项目上起过作用,尽管我还没有在大项目上尝试过。要使用它,请从文件树中选择project文件夹(默认位于屏幕左边),然后按shift-F6打开rename对话框。您可以在这里输入您的新名称并预览更改,这将有助于防止出现意外。如果你对预览很满意,点击窗口底部的“Do Refactor”按钮。

This is also a useful way to rename Django apps.

这也是重命名Django应用程序的一种有用方法。

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.

您可以通过右键单击文件夹/项并将鼠标悬停在Refactor子菜单上来访问相同的功能。或者按ctrl+shift+a,搜索rename。

#2


12  

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

我使用的是Windows操作系统,但其他操作系统可能也是如此。

  1. Close PyCharm, open the directory in Windows Explorer (or your favorite file manager).
  2. 关闭PyCharm,在Windows资源管理器(或你最喜欢的文件管理器)中打开目录。
  3. Rename the project directory
  4. 重命名项目目录
  5. Rename the subdirectory of the same name that is inside your project directory
  6. 重命名项目目录中相同名称的子目录。
  7. Open the .idea directory (in the project folder), rename the .iml file
  8. 打开.idea目录(在项目文件夹中),重命名.iml文件
  9. Also in the .idea directory, open the .name file in a text editor and change the name in there
  10. 在.idea目录中,在文本编辑器中打开.name文件并在其中更改名称
  11. Open the project in PyCharm again.
  12. 在PyCharm再次打开项目。
  13. In the settings.py file, you'll need to update the path specified in TEMPLATE_DIRS
  14. 在设置。py文件,您需要更新TEMPLATE_DIRS中指定的路径。

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

您可能还想更新您的运行/调试配置(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.

您将需要替换一些旧项目名称的其他出现。在PyCharm中,Ctrl-Shift-F将允许你搜索所有文件的内容来找到这些东西。

#3


10  

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

也许:在“项目”窗口中右键单击根文件夹,选择重构->重命名,选择“重命名项目”

#4


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.

svass的回答对我起了作用,除了我必须在项目的.idea目录内的文件中手动更改旧项目名的实例。

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

如果您将cd存储到项目目录中,并使用grep获取旧的项目名称

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