我遇到了一个似乎可能与djangocode相关的线程,但它并没有真正帮助.我正在尝试保存一个模型,它正在抛出异常.我认为这可能与我的模型中两次引用相同的外键有关.它也可能与其中一个外键字段中unique = True的定义有关.我不知道
class User_Message(models.Model):
recipient=models.ForeignKey(User, unique=True, related_name="recipients")
subject=models.CharField(max_length=100)
sender=models.ForeignKey(User, related_name="senders")
message=models.TextField(max_length=500)
sent=models.DateField(auto_now_add=True)
def __unicode__(self):
return self.subject
if request.method=="POST" and request.POST['id_message']:
messageform=User_MessageForm(request.POST)
recipient=[] #receiver of mail must be a list
recipient.append(post.user)
if messageform.is_valid:
message=messageform.save(commit=False)
message.sender=user
message.recipient=post.user
return HttpResponse('%s %s' %(user,post.user))
message.save()
#send the email
subject=messageform.cleaned_data['id_subject']
body=messageform.cleaned_data['id_message']
try:
send_mail(subject, body, sender, recipient)
except BadHeaderError:
return HttpResponse('Invalid header found.')
Run Code Online (Sandbox Code Playgroud)
它失败了,"messageform.save(commit = False).我认为这个陈述是失败证明.
modelform接收的POST数据包含主题和消息字段.我的模型成功验证了此数据.
是相关名称,唯一=真......什么给出?
谢谢
我(2, 2, 4, 'final', 0)在 docker 中使用 Django,但我可以在内部 bash 来打开或执行所需的任何内容。但我无法调试。(如何在 Django 中调试,好方法?说明了一些方法,但对我不起作用)
在我的内部views.py有各种功能,例如这里的这个。
def visGraph(request):
showgraph = 'Graphen'
selectDB = request.GET.get('selectDB', '')
__import__("pdb").set_trace()
title += " <i>"+showgraph+"</i> ("+selectDB+")"
Run Code Online (Sandbox Code Playgroud)
它工作正常,直到我填写 pdb,添加调试器会使我的应用程序立即崩溃:
> /code/DjangoGraphen/views.py(74)visGraph()
-> title += " <i>"+showgraph+"</i> ("+selectDB+")"
(Pdb)
Internal Server Error: /DjangoGraphen/visGraph
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response …Run Code Online (Sandbox Code Playgroud) 我正在处理hibernate,当我打开我当前的项目时,我发现我的Session-Factory已被弃用:
AnnotationConfiguration af = new AnnotationConfiguration();
SessionFactory factory = af.configure().buildSessionFactory();
Session session = factory.openSession();
Run Code Online (Sandbox Code Playgroud)
AnnotationConfiguration现在似乎已经被弃用了......所以我检查了JavaDoc并告诉它它被移动到:
org.hibernate.cfg.Configuration
我的代码到目前为止工作得很好,实际上我不想改变它......但是我用Google搜索并发现有人问自己同样的问题为什么SessionFactory需要更改... http://rgordon.co.uk/博客/ 2012/02/24 /休眠-请-不要-贬低自己动手/
该文章是从2012年开始的(所以不是那么老......)并以这种方式描述所有内容:
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(properties);
ServiceRegistry serviceRegistry = serviceRegistryBuilder.buildServiceRegistry();
Configuration configuration = new Configuration().addClass(FeedTradePersistable.class);
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Run Code Online (Sandbox Code Playgroud)
我实现了那个.JavaDoc再次证明了错误!已过时.它指的是:
org.hibernate.boot.registry.StandardServiceRegistryBuilder
我再次用Google搜索.结果不那么令人满意......
我开始修改代码......
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
Run Code Online (Sandbox Code Playgroud)
抛出异常......
org.hibernate.HibernateException:未设置'hibernate.dialect'时,Connection不能为null
在线:
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Run Code Online (Sandbox Code Playgroud)
我很确定这是因为我没有指定任何配置设置.实际上,我不想.我对hibernate.cfg.xml感到满意.
我玩了一下配置.addFile(.. - 不是那么成功......
有没有人对此有所了解?谢谢
更新:(hibernate.cfg.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC …Run Code Online (Sandbox Code Playgroud) java hibernate sessionfactory hibernate-annotations sql-server-2012-express
我想在另一个现有的管道中加载 Jenkins-Pipeline-File。另外我是詹金斯的新手,我想我只是在监督一些事情
我的主脚本中有 load 命令,但它的行为并不像预期的那样(pipe_name 是常规字符串参数):
pipeline{
agent any
stages{
stage('Load Pipeline') {
steps{
load pipe_name
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我要加载的管道:
pipeline{
agent any
stages{
stage('Do Stuff') {
steps{
//Do Stuff
}
}
stage('Do even more stuff') {
steps{
#More Stuff to be done
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这失败了:
java.lang.IllegalStateException: Only one pipeline { ... } block can be executed in a single run.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at …Run Code Online (Sandbox Code Playgroud) 我在 Docker 中有一个 Django 服务器,并且希望能够远程调试我的脚本。箭头键不起作用。我越来越
(Pdb) ^[[A
Run Code Online (Sandbox Code Playgroud)
而不是有用的东西。我只是在 Ubuntu 上使用普通终端。没有 IDE 或任何奇特的东西。
正如这里所述,我重写了我的 docker-compose 并且它可以很好地使用此行:
__import__("remote_pdb").set_trace(host='0.0.0.0', port=4444)
Run Code Online (Sandbox Code Playgroud)
通过 telnet,我可以使用pdb 的大多数telnet 0.0.0.0 4444功能:
不起作用的是箭头键。有人也遇到了这个问题,我安装了readline,因为这个人也遇到了同样的问题:Python 交互模式历史记录和箭头键
dnf install ncurses-devel
pip3 install readline
Run Code Online (Sandbox Code Playgroud)
没有变化。(安装有效。我可以导入readline)。我假设问题可能来自 telnet。所以我正在考虑切换到ssh -t。
但现在我应该登录:
ssh -t 0.0.0.0 -P 4444
qohelet@0.0.0.0's password:
Run Code Online (Sandbox Code Playgroud)
没有密码。这只是一个 Docker。我也不知道用户名。
我一直在寻找,2017 年刚刚打来电话。我应该使用gnureadline。没有不同:
(Pdb) import gnureadline
(Pdb) ^[[A
Run Code Online (Sandbox Code Playgroud)
我现在被困住了。
它发生在我的项目中,我不得不扩展一个现有的表,其中包含更多列.不幸的是我不能改变或删除/重新创建它,所以我只选择创建另一个具有1:1-Relationship的表,并在具有插入/更新/删除触发器的视图中合并它们.
到目前为止,插入和删除工作,但我有更新触发器的问题.成功的信息更令人困惑.
View看起来像这样:
Create View [dbo].[JoinedGroups] as
SELECT [dbo].[MaterialGroups].[GroupID]
,[Name]
,[SupGroup_ID]
,[ExtGroup_ID]
FROM [dbo].[MaterialGroups]
left outer join [dbo].[MaterialGroups_Extend]
ON [dbo].[MaterialGroups].[GroupID]=[dbo].[MaterialGroups_Extend].[GroupID]
Run Code Online (Sandbox Code Playgroud)
如上所述,新的附加表尚未填充,这就是左外连接的原因,但如果你有不同的想法,请告诉我.
触发:
CREATE TRIGGER [dbo].[UpdateTriggerJG] ON [dbo].[JoinedGroups]
INSTEAD OF Update
AS
BEGIN
IF EXISTS (SELECT * FROM [dbo].[MaterialGroups_Extend] E,inserted I WHERE E.[GroupID] = I.[GroupID])
BEGIN
UPDATE [dbo].[MaterialGroups_Extend]
SET [SupGroup_ID] = I.[SupGroup_ID]
,[ExtGroup_ID] = I.[ExtGroup_ID]
FROM [Buran].[dbo].[MaterialGroups_Extend] E,inserted I
WHERE E.[GroupID] = I.[GroupID]
END
ELSE
BEGIN
INSERT INTO [dbo].[MaterialGroups_Extend]
([GroupID]
,[SupGroup_ID]
,[ExtGroup_ID])
SELECT [GroupID]
,[SupGroup_ID]
,[ExtGroup_ID]
FROM inserted
END
UPDATE [dbo].[MaterialGroups] …Run Code Online (Sandbox Code Playgroud) 我很难尝试使用itextpdf生成包含希腊字母的PDF文件.我正在从外部源读取字符串作为UTF-8字符串.英语字母出现在结果中但不出现在希腊语中.搜索问题,我认为它可能与使用的字体有关.如果这是问题,我不知道要使用什么ttf文件.这是我如何创建字体
BaseFont bfTimes = BaseFont.createFont(FontFactory.HELVETICA,"UTF-8", BaseFont.EMBEDDED);
Font times = new Font(bfTimes, 12, Font.BOLD);
Run Code Online (Sandbox Code Playgroud)
衷心感谢任何帮助!
我在几行中的几个文件中出现了几次特定字符串grep.
$ grep -rn --include="*.cpp" mystring
lib/mlib/actionbuttonrule.cpp:300: mystring Foobar...
lib/mlib/actionbuttonrule.cpp:314: other mystring
lib/mlib/item.cpp:3025: /* mystring**/
lib/mlib/item.cpp:3082: mystring Foobar...
lib/mlib/item.cpp:3095: Foo mystring bar
Run Code Online (Sandbox Code Playgroud)
我想在相应的行上按顺序打开这些文件.我试着这样做vim,但到目前为止,在打开线路时没有成功.一定不能vim或者grep,但我认为那里必须有某种功能......
我正在使用Ubuntu-PC创建带有iText的PDF,部分是中文版.为了阅读它们,我使用了Evince.到目前为止几乎没有任何问题
在我的电脑上,我尝试了以下三个BaseFonts,他们成功地工作了:
bf = BaseFont.createFont("MSungStd-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
bf = BaseFont.createFont("MSung-Light","UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
Run Code Online (Sandbox Code Playgroud)
不幸的是,在使用Acrobat-Reader在Windows上打开最终PDF时,文档无法再正确显示.
在我搜索字体以获得解决方案之后,我来到论坛,以可理解的方式解释问题(这里使用了MSung-Light):http://community.jaspersoft.com/questions/531457/chinese-font-不能待看到
您正在使用PDF中的内置中文字体.我不确定这种字体能否同时支持英文和中文,或混合语言.
使用Acrobat Reader内置字体的优点是它可以生成较小的PDF文件,因为它依赖于显示PDF的客户端计算机上可用的字体,通过预先安装的Acribat Asian Font Pack.
但是,当我们研究与内置韩文字体相关的类似问题时,使用PDF内置字体具有通过在不同机器上进行测试而发现的一些缺点.
我该怎么办呢?能够复制中文字母并不是那么重要.iText可以将段落转换为图像吗?或者有更好的解决方案吗?
我使用的是 Ubuntu 16.04 和 OpenCV 2.4.9,我的非常简单的示例程序总是无法构建。我正在 CLion 上构建。
由于我对 OpenCV 有点陌生,我有一些问题来缩小问题范围。我尝试了两个不同的程序。
第 1 号是这个:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main(int argc, char **argv) {
IplImage *img = cvLoadImage(argv[1]);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1" );
}
Run Code Online (Sandbox Code Playgroud)
失败的原因是:
Scanning dependencies of target untitled
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
[100%] Linking CXX executable untitled
CMakeFiles/untitled.dir/main.cpp.o: In function `main':
/home/computervision/CLionProjects/untitled/main.cpp:7: undefined reference to `cvLoadImage'
/home/computervision/CLionProjects/untitled/main.cpp:8: undefined reference to `cvNamedWindow'
/home/computervision/CLionProjects/untitled/main.cpp:9: undefined reference to `cvShowImage'
/home/computervision/CLionProjects/untitled/main.cpp:10: undefined …Run Code Online (Sandbox Code Playgroud)