VSCode 中的 Django 目录不一样

发布于 2025-01-18 21:55:28 字数 520 浏览 2 评论 0原文

from django.utils.translation import ugettext_lazy

在过去的两个小时中,我在这条线上遇到了问题,但我尝试了每种方法,但失败了,但是当我检查 django.utils.utils.translations.translation 的目录时,是 ugetText_lazy>的其他人和目录。同时还有其他人 django.utils.translation search ugetText_lazy 在C中: init _

。 jedilsp \ jedi \ third_party \ django-stubs \ django-stubs \ utils_ init> init

_ “ rel =“ nofollow noreferrer”>

此处。

from django.utils.translation import ugettext_lazy

I got problem in this line for last 2 hours I try every method but failed, but when I checked the directory of django.utils.translation is someone else and directory of ugettext_lazy has someone else meanwhile
django.utils.translation search ugettext_lazy in C:\Users\admin\AppData\Local\Programs\Python\Python310\Lib\site-packages\django\utils\translation_init_.py

but the ugettext_lazy directory has in C:\Users\admin\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\lib\jedilsp\jedi\third_party\django-stubs\django-stubs\utils_init_.py

How to make it same directory

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏末 2025-01-25 21:55:31

文件扩展名末尾的 i 表示该文件是一个接口,您可以阅读更多内容 在此相关问题中。一个答案是:

“这个文件只是一个 Python 框架,具有正确的结构、调用签名和返回值,以对应于模块中指定的函数、属性、类和方法。” ->本例中的模块是 translation

如果您使用的是 Django 版本 > 2.2 ugettext_lazy 在 v2.2 中已弃用,并且在 django v3+ 中不再使用。检查您的 Django 文档有关延迟翻译的版本,您可以尝试:

from django.utils.translation import gettext_lazy as _

The i at the end of the files extension means that the file is an interface you can read more in this related Q. One answer says:

"This file is merely a Python skeleton with the proper structure, call signature, and return values to correspond to the functions, attributes, classes, and methods specified in a module." -> the module in this case is translation

And if you are using a Django version > 2.2 ugettext_lazy was deprecated in v2.2 and no longer used in django v3+. Check your version of Django’s documentation regarding lazy translation, you could try:

from django.utils.translation import gettext_lazy as _
无人接听 2025-01-25 21:55:31

有两种简单的方法可以

其他目录中复制该行或功能或类

我明白了,

from django.utils.translation import *

I got it there is two simple method to do that one is

copy that line or function or class from other directory and paste it to the directory where he finds that

Second is

use * after 'import' for example

from django.utils.translation import *
冰火雁神 2025-01-25 21:55:31

如图所示,实际上,VSCODE告诉我们,此处的导入文件已经是错误的文件,并且该文件不包括在此软件包中。如上所述,如果无法确保导入的内容,则可以使用“*”。

enter image description here

As shown in the picture, in fact, vscode has told us that the imported file here is already a wrong file, and it is not included in this package. As mentioned above, you could use "*" if you can't ensure the content to import.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文