我使用Pycharm重构函数重命名了我的项目和目录,现在它已经坏了。我更改了所有可以找到的依赖项,但是似乎有一些时髦的错误发生了,我绝对无法弄清楚。 错误消息:
Traceback (most recent call last):
File "C:/Users/user1/Projects/platform_back/manage.py", line 21, in <module>
main()
File "C:/Users/user1/Projects/platform_back/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\management\__init__.py", line 244, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\management\__init__.py", line 37, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Users\user1\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 3, in <module>
from django.core.management.commands.runserver import (
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\management\commands\runserver.py", line 10, in <module>
from django.core.servers.basehttp import (
File "C:\Users\user1\Projects\platform_back\venv\lib\site-packages\django\core\servers\basehttp.py", line 14, in <module>
from wsgiref import simple_server
File "C:\Users\user1\AppData\Local\Programs\Python\Python37\lib\wsgiref\simple_server.py", line 17, in <module>
from platform import python_implementation
ImportError: cannot import name 'python_implementation' from 'platform' (C:\Users\user1\Projects\platform_back\platform\__init__.py)
似乎正在从虚拟环境外部调用目录,但是我不知道这是否是故意的。
初始化 .py:
from .dev import *
dev.py:
from .settings import *
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware')
INSTALLED_APPS.append('debug_toolbar')
INTERNAL_IPS = ('127.0.0.1', 'localhost')
我知道我可能可以用一个新名称重新创建整个应用程序,但是我觉得这里有一个教训。任何帮助将不胜感激
答案 0 :(得分:1)
您无法调用您的项目platform
–这是this built-in module保留的名称。
回溯的最后几行
File "wsgiref\simple_server.py", line 17, in <module>
from platform import python_implementation
ImportError: cannot import name 'python_implementation'
from 'platform' (C:\Users\user1\Projects\platform_back\platform\__init__.py)
是wsgiref
,WSGi服务器实现模块(也是内置的),试图导入platform.python_implementation()
,但是由于您的模块也称为platform
,因此失败。
答案 1 :(得分:0)
如果重命名目录,则还应该更改<script>
$(document).ready(function(){
// submit customers form function
$("#shoutOutForm").unbind('submit').bind('submit', function() {
$('.form-group').removeClass('has-error').removeClass('has-success');
$('.text-danger').remove();
var sigaw = $("#sigaw").val();
var username = $("#username").val();
if(sigaw == "") {
$("#sigaw").after('<p class="text-danger">Shout Out field is required</p>');
$('#sigaw').closest('.form-group').addClass('has-error');
} else {
// remov error text field
$("#sigaw").find('.text-danger').remove();
// success out for form
$("#sigaw").closest('.form-group').addClass('has-success');
}
if(sigaw) {
var form = $(this);
// button loading
$("#shoutOutBtn").button('loading');
$.ajax({
url : form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'json',
beforeSend: function() {
$('#shoutOutBtn').html("<div class='spinner-border text-light' role='status'></div> Shouting ...");
$("#shoutOutBtn").prop('disabled', true); // disable button
},
success:function(response) {
// button loading
$("#shoutOutBtn").button('reset');
if(response.success == true) {
// reload the manage member table
// reset the form text
$("#shoutOutForm")[0].reset();
// remove the error text
$(".text-danger").remove();
// remove the form error
$('.form-group').removeClass('has-error').removeClass('has-success');
$('#buttonAlert').html('<div class="alert alert-success">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="fa fa-check"></i></strong> '+ response.messages +
'</div>');
$(".alert-success").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
$("#shoutOutBtn").prop('disabled', false); // disable button
$('#shoutOutBtn').html("<i class=\"fa fa-check\"></i> Save");
});
}); // /.alert
}else{
$("#shoutOutForm")[0].reset();
// remove the error text
$(".text-danger").remove();
// remove the form error
$('.form-group').removeClass('has-error').removeClass('has-success');
$('#buttonAlert').html('<div class="alert alert-danger">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="fa fa-check"></i></strong> '+ response.messages +
'</div>');
$(".alert-danger").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
$("#shoutOutBtn").prop('disabled', false); // disable button
$('#shoutOutBtn').html("<i class=\"fa fa-cross\"></i> Save");
});
}); // /.alert
}
} // /success
}); // /ajax
} // if
return false;
}); submit customers form function
});
</script>
和manage.py
的导入。这些文件很可能仍在查看旧的导入文件。