使用Pycharm,我得到一些不同的结果,然后从终端运行命令.我注意到,在我更新视图后,只有在从IDE运行测试时才会出现"尚未加载应用程序"的异常.
如果我通过终端"python3 manage.py test"运行测试,则没有问题.
IDE运行测试此视图文件没有问题
def wine_data(request):
return HttpResponse("<html><title>Wine Data</title></html>")
Run Code Online (Sandbox Code Playgroud)
如果我将视图文件更改为:
def wine_data(request):
return render(request, 'wine_data.html')
Run Code Online (Sandbox Code Playgroud)
我收到此错误(仅在从IDE运行时)
/ home/codeamend/Projects/python/OldBullTavern/venv/bin/python /opt/pycharm-professional/helpers/pycharm/utrunner.py /home/codeamend/Projects/python/OldBullTavern/obt/wine/tests.py true Testing上午11:38开始......
错误回溯(最近一次调用最后一次):文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py",第86行,在getitem中 返回self ._engines [别名] KeyError:'django'
在处理上述异常期间,发生了另一个异常:
回溯(最近一次调用最后一次):文件"/home/codeamend/Projects/python/OldBullTavern/obt/wine/tests.py",第16行,在test_wine_data_loads_correct_html响应= wine_data(请求)文件"/ home/codeamend/Projects/python/OldBullTavern/obt/wine/views.py",第6行,在wine_data中返回render(request,'wine_data.html')File"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/ site-packages/django/shortcuts.py",第67行,在render template_name,context,request = request,using = using)文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site -packages/django/template/loader.py",第96行,在render_to_string template = get_template(template_name,using = using)文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site- packages/django/template/loader.py",第26行,在get_template engines = _engine_list(using)File"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template /loader.py",第143行,在_engine_list中 turn engine.all()如果使用is None else [engines [using]] File"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py" ,第110行,在所有返回[self [别名]为自己的别名]文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py" ,第110行,作为回报[self [别名]为自己的别名]文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py",第101行,在getitem 引擎= engine_cls(params)文件"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py",第31行,在init options ['libraries'] = self.get_templatetag_libraries(libraries)File"/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py" ,第49行,在get_templatetag_libraries libraries = get_installed_libraries()文件"/ home/codeamend/Projects/python/OldBullTa vern/venv/lib/python3.5/site-packages/django/template/backends/django.py",第132行,在apps.get_app_configs()中的app_config的get_installed_libraries中)文件"/ home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py",第137行,在get_app_configs中self.check_apps_ready()文件"/ home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py",第124行,在check_apps_ready中引发AppRegistryNotReady("应用程序尚未加载.")django.core.exceptions.AppRegistryNotReady:尚未加载应用程序.
进程以退出代码0结束
有任何想法吗?
我浏览了GraphQL的对象类型教程,然后阅读了文档的构造类型部分.我通过创建一个简单的做了一个类似的风格审判case convention converter
.为什么?学习 :)
转换为使用时GraphQLObjectType
,我希望得到相同的结果buildSchema
.
buildSchema
使用type CaseConventions
但在使用GraphQLObjectType
时没有设置type
?我在这里做错了吗?rootValue
对象吗?GraphQLObjectType
buildQuery
感谢您的耐心和帮助.
class CaseConventions {
constructor(text) {
this.text = text;
this.lowerCase = String.prototype.toLowerCase;
this.upperCase = String.prototype.toUpperCase;
}
splitTargetInput(caseOption) {
if(caseOption)
return caseOption.call(this.text).split(' ');
return this.text.split(' ');
}
cssCase() {
const wordList = this.splitTargetInput(this.lowerCase);
return wordList.join('-');
}
constCase() {
const wordList = this.splitTargetInput(this.upperCase);
return wordList.join('_');
}
}
module.exports = CaseConventions; …
Run Code Online (Sandbox Code Playgroud) 我不认为这是重复的.我已经看了很多类似问题的答案.
请注意:这运行完全正常,django找到所有静态文件.
更新:看起来这是一个PyCharm错误.如果我将静态移动到我的app目录中,PyCharm可以解析它.但是,我在主src dir中有这个静态因为多个应用程序将使用CSS.现在它运行,Django对此没有任何问题.我觉得这是一个PyCharm错误.
PyCharm已经建立,其他一切似乎都与Pycharm提供的Django项目有关.
Pycharm无法解决,这意味着我无法使用自动完成,这很烦人.如果我点击ctrl-space,弹出的唯一目录是admin.这意味着PyCharm完全忽略了我的静态目录.
我也试过把它变成模板目录和资源总监.也没有运气.
{% load static %} <!-- {% load staticfiles %} -->
...
<link rel="stylesheet" href="{% static ''%}">
<link rel="stylesheet" href="{% static 'css/skeleton.css' %}">
<link rel="stylesheet" href="{% static 'css/custom.css' %}">
...
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常.虽然PyCharm没有找到网址.
INSTALLED_APPS = [
'django.contrib.staticfiles',
# admin specific
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_URL = '/static/'
Run Code Online (Sandbox Code Playgroud)
这个中间件在 Supertest 中运行时没有出现:
app.use((err, req, res, next) => {
// WHY DOES Supertest NOT SHOW THIS ERROR??
console.log("error: ", err.message);
res.status(422).send({ error: err.message });
});
Run Code Online (Sandbox Code Playgroud)
我只是花了一些愚蠢的时间试图找到这个错误:
Driver.findByIdAndDelete(driverId) // Remove NOT Delete
.then(driver => {
res.status(204).send(driver)
})
...
Run Code Online (Sandbox Code Playgroud)
在使用 Postman 时,中间件正确地将错误显示为对正文的响应,但在运行测试时却没有。
我打开了 2 个终端窗口,运行 npm run:test
并且start
在运行 Postman 之前,这里没有任何帮助。
包.json:
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"mocha": "^3.2.0",
"mongoose": "^4.8.6"
},
"devDependencies": {
"nodemon": "^1.11.0",
"supertest": "^3.0.0"
}
Run Code Online (Sandbox Code Playgroud) 我正在使用jQuery来尝试查找哪些ID具有某个类名.这对我来说很重要的原因是我使用jQuery中的toggleClass()来显示和隐藏某些div,当选择一个按钮时我想要一个视口来显示或隐藏.我有两个个人目标:一个是在jquery中找到一种方法,另一个是了解如何在javascript中执行此操作.我知道javascript会更先进,我准备好了.
就这样毫无疑问我添加了代码.让我们首先看一下名为CodeAmend的个人托管网页,这是代码
*******HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Player</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<p>CodePlayer</p>
<nav>
<ul>
<li id="html-button" class="toggle selected no-highlight">HTML</li>
<li id="css-button" class="toggle selected no-highlight">CSS</li>
<li id="js-button" class="toggle selected no-highlight">JS</li>
<li id="result-button" class="toggle selected no-highlight">Result</li>
</ul>
</nav>
<div id="run-button" class="no-select">Run</div>
</div>
<div id="html-container" class="code-container">
<div class="code-label">HTML</div>
<textarea>Code</textarea>
</div>
<div id="css-container" class="code-container">
<div …
Run Code Online (Sandbox Code Playgroud) 我正在测试 Electron,特别是使用executeJavaScript。我的项目使用 POST 请求登录网站,然后执行一些工作并使用同一会话加载第二个 URL。在第二个 URL 中,我需要执行 JS,但我不确定我做错了什么。
在此示例中,我创建了一个简化版本,模拟访问两个 URL 并在第二个 URL 上执行 JS。对这里发生的事情有什么想法吗?
const {app, BrowserWindow} = require('electron');
let win;
function createWindow() {
win = new BrowserWindow({width: 1000, height: 600})
win.openDevTools();
// First URL
win.loadURL('https://www.google.com')
// Once dom-ready
win.webContents.once('dom-ready', () => {
// THIS WORKS!!!
win.webContents.executeJavaScript(`
console.log("This loads no problem!");
`)
// Second URL
win.loadURL('https://github.com/electron/electron');
// Once did-navigate seems to function fine
win.webContents.once('did-navigate', () => {
// THIS WORKS!!! So did-navigate is working!
console.log("Main view logs this no problem...."); …
Run Code Online (Sandbox Code Playgroud)