小编Say*_*yse的帖子

ArrayField缺少1个必需的位置参数

我导入了以下头文件

from django.contrib.postgres.fields import ArrayField
Run Code Online (Sandbox Code Playgroud)

在模型中使用以下内容

question_array = ArrayField(models.IntegerField, blank=True,)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Traceback (most recent call last)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files (x86)\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen …
Run Code Online (Sandbox Code Playgroud)

python django

9
推荐指数
1
解决办法
1857
查看次数

里面似乎没有任何图案。如果您在文件中看到有效模式,则问题可能是由循环导入引起的

我有

里面似乎没有任何图案。如果您在文件中看到有效模式,则问题可能是由循环导入错误引起的。

我在子应用的 urls.py 中写的

from django.conf.urls import url
from django.contrib.views import login,logout

urlpatterns = [
    url(r'^login/$', login,
        name='login'),
    url(r'^logout/$', logout, name='logout')
]
Run Code Online (Sandbox Code Playgroud)

在父应用程序的 urls.py 中,

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('accounts.urls')),
    url(r'^api/', include('UserToken.urls')),
    url(r'^UserDataAPI/', include('UserDataAPI.urls', namespace='UserDataAPI')),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Run Code Online (Sandbox Code Playgroud)

我正在考虑孩子或父应用程序的 urls.py,但我不知道如何修复它。我该怎么办?

python django

9
推荐指数
1
解决办法
2万
查看次数

VS 2013断点目前不会被击中.没有为此文档加载任何符号

VS2013,Windows 8.1,Windows Phone 8 c#app断点不起作用,我得到的断点当前不会被击中.没有为此文档加载符号错误我需要做什么?

图片

c# breakpoints visual-studio-2013

7
推荐指数
2
解决办法
2万
查看次数

Amazon.Runtime.AmazonServiceException:无法找到凭据

我们使用连接到AWS SNS服务的AWS SDK工具包在vs 2010中设计了WebService应用程序.

当我们直接从VS 2010开发工作室运行时,它非常有效,但是当我们将Web服务发布到本地IIS或专用的Web服务器时,它会失败并显示以下错误消息.

Amazon.Runtime.AmazonServiceException: Unable to find credentials

Exception 1 of 4:
System.ArgumentException: Path cannot be the empty string or all whitespace.
Parameter name: path
   at System.IO.Directory.GetParent(String path)
   at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation)
   at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation)
   at Amazon.Runtime.EnvironmentAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.&lt;Reset&gt;b__1()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 4:
System.ArgumentException: Path cannot be the empty string or all whitespace.
Parameter name: path
   at System.IO.Directory.GetParent(String path)
   at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation)
   at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation)
   at Amazon.Runtime.FallbackCredentialsFactory.&lt;Reset&gt;b__2()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception …
Run Code Online (Sandbox Code Playgroud)

c# amazon-web-services

7
推荐指数
1
解决办法
1万
查看次数

获取对象时如何处理"匹配查询不存在"

当我想选择具有get()函数的对象时

personalProfile = World.objects.get(ID=personID)
Run Code Online (Sandbox Code Playgroud)

如果get函数没有返回查找值,则"匹配查询不存在".发生错误.

如果我不需要这个错误,我将使用try和except函数

try:
   personalProfile = World.objects.get(ID=personID)
except:
   pass
Run Code Online (Sandbox Code Playgroud)

但我认为这不是我使用以来最好的方法

except:
      pass
Run Code Online (Sandbox Code Playgroud)

请推荐一些想法或代码示例来解决这个问题

django django-views python-2.7

7
推荐指数
1
解决办法
1万
查看次数

无法在django(使用python-opencv)项目中找到面部(面部检测)

这个代码块(在views.py中)由URL触发.导入cv2时没有问题.(使用virtualenvwrapper尝试的同样的事情显示相同的结果(添加所有必需的库之后)相机初始化和....

def caminit(request):  
  cam.open(0)
  img=cam.read()
  cv2.imwrite("snap"+".jpg",img[1])
  cam.release()                                #takes the instant pic

  faceCascade =cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
  eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
Run Code Online (Sandbox Code Playgroud)

检查时 print type(faceCascade) 给出<type 'cv2.CascadeClassifier'>.对象已创建.

继续前进 caminit

image = cv2.imread("snap.jpg")

# when checked with image.dtype it shows correct uint8 also image.shape shows correct data {Eg: (480, 640, 3)}

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
Run Code Online (Sandbox Code Playgroud)

现在关键部分"寻找面孔的数量"

print "Found {0} faces!".format(len(faces))
Run Code Online (Sandbox Code Playgroud)

终端输出:

Found 0 faces!
Run Code Online (Sandbox Code Playgroud)

为什么会这样? …

django opencv python-2.7 haar-classifier

7
推荐指数
1
解决办法
828
查看次数

来自django 1.9中django.views.generic.simple import direct_to_template的等价物是什么

我想创建我的主页,index.html它位于名为as的模板目录中templates/castle_tm/index.html,但是url显示

"没有名为简单的模块".

基于通用的视图在django> 1.4中已弃用.现在,我如何将主页重定向到index.html

urls.py

from django.conf.urls import url, patterns, include
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
from castle import views
from django.views.generic.simple import direct_to_template
admin.autodiscover()
url(r'^api/casinova$', direct_to_template,{"template":"castle_tm/index.html"}),
Run Code Online (Sandbox Code Playgroud)

python django

7
推荐指数
2
解决办法
4251
查看次数

如何比较 Django 中的两个日期时间字段

我已用于datetime.datetime.now()存储datefield在我的模型中,该模型另存为2016-06-27 15:21:17.248951+05:30. 现在我想将datefielddatetime从前端获取的值进行比较,例如Thu May 26 2016 00:00:00 GMT 0530 (IST). Django 应该如何查询模型来比较两个日期字段?

# models.py

datefield = models.DateTimeField(blank=True,null=True)
Run Code Online (Sandbox Code Playgroud)

我曾尝试datefield通过使用Python 的函数split()remove()函数来转换从前端获取,以将其创建为2016-06-27 13:25:35.

但仍然没有解决方案,Null甚至我将这样的相同日期值 (2016-06-27 13:25:35) 值与此 (2016-06-27 12:36:34.898593+00) 值进行比较,作为两者中的日期值是一样的。

我已经使用简单的 Django 查询进行了检查,如下所示:

company_details.objects.filter(datefield=datefield).only('par1','par2',...)
Run Code Online (Sandbox Code Playgroud)

django

7
推荐指数
1
解决办法
8568
查看次数

如何获得stackedBar ChartJs中的总值之和

我正在尝试获取stackedBar的所有值的总和,并在工具提示中包含此总数.

注意:我的数据集不是静态的,这是一个例子

var barChartData = {
        labels: ["January", "February", "March", "April", "May", "June", "July"],
        datasets: [{
            label: 'Corporation 1',
            backgroundColor: "rgba(220,220,220,0.5)",
            data: [50, 40, 23, 45, 67, 78, 23]
        }, {
            label: 'Corporation 2',
            backgroundColor: "rgba(151,187,205,0.5)",
            data: [50, 40, 78, 23, 23, 45, 67]
        }, {
            label: 'Corporation 3',
            backgroundColor: "rgba(151,187,205,0.5)",
            data: [50, 67, 78, 23, 40, 23, 55]
        }]

    };

    window.onload = function() {
        var ctx = document.getElementById("canvas").getContext("2d");
        window.myBar = new Chart(ctx, {
            type: 'bar',
            data: barChartData,
            options: { …
Run Code Online (Sandbox Code Playgroud)

django chart.js

7
推荐指数
4
解决办法
1万
查看次数

字符串排序问题

我有以下编译为Sort.exe的C#代码:

using System;
using System.Collections.Generic;

class Test
{
    public static int Main(string[] args)
    {
        string text = null;
        List<string> lines = new List<string>();
        while((text = Console.In.ReadLine()) != null)
        {
            lines.Add(text);
        }

        lines.Sort();

        foreach(var line in lines)
            Console.WriteLine(line);

        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个文件input.txt,其中包含以下5行:

x000000000000000000093.000000000
x000000000000000000037.000000000
x000000000000000100000.000000000
x000000000000000000538.000000000
x-00000000000000000020.000000000
Run Code Online (Sandbox Code Playgroud)

现在,如果我在命令提示符下运行它,则输出如下:

C:\Users\girijesh\AppData\Local\Temp>sort < input.txt
x000000000000000000037.000000000
x000000000000000000093.000000000
x-00000000000000000020.000000000
x000000000000000000538.000000000
x000000000000000100000.000000000
Run Code Online (Sandbox Code Playgroud)

我无法理解字符串排序是什么样的字符串开头的字符串x-(输出中的第3行)出现在字符串的中间x0.第三行应该位于顶部或底部.Excel也显示相同的行为.

c# sorting

6
推荐指数
1
解决办法
145
查看次数