javascript

git

java

python

git-remote

c++

github

django

c#

reactjs

c++-faq

git-checkout

generator

coroutine

spring-mvc

reflection

javascript-objects

html5

analytics

node.js

关于Django中的IP 0.0.0.0

我们有一台运行Django支持站点的服务器。 由于我们要测试该站点,因此我们使用的是Django的内置开发服务器(即0.0.0.0)。 但是我很好奇以下命令的ip:

python manage.py runserver 0.0.0.0:80

这将导致一个运行中的站点,我们可以使用服务器的ip远程访问该站点。
但是,当使用0.0.0.0代替时:

python manage.py runserver 127.0.0.1:80

没有人可以使用另一台计算机的服务器IP访问该站点。

所以为什么? 0.0.0.0到底是什么意思(Google说这是默认路由)? 为什么不能远程访问127.0.0.1:80

trans by 2020-08-12T04:34:46Z

python-Django URL模式-字符串参数

具有数字参数的Django网址格式为:

url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail')

如果我的poll_id不是数字而是一个字符串,那么正确的语法是什么?

trans by 2020-08-11T04:45:24Z

我的项目(Django)有任何更改时如何自动运行测试?

目前,在对django项目进行重大更改后,我偶尔会运行python manage.py test。 每当我更改并将文件保存在项目中时,是否可以自动运行那些测试? 尽早发现错误将很有用(我知道Rails在rspec中有类似的东西)。 我正在用鼻子和Django-nose。 提前致谢。

trans by 2020-08-10T14:51:56Z

python-Django 1.11 TypeError上下文必须是字典而不是Contex

刚刚在我的一种表格上收到Sentry错误message = get_template('email_forms/direct_donation_form_email.html').render(Context(ctx))。 我知道它与Django 1.11有关,但是我不确定要进行哪些更改以修复它。

违规线

message = get_template('email_forms/direct_donation_form_email.html').render(Context(ctx))

整个视图

def donation_application(request):
    if request.method == 'POST':
        form = DirectDonationForm(data=request.POST)
        if form.is_valid():
            stripe.api_key = settings.STRIPE_SECRET_KEY
            name = request.POST.get('name', '')
            address = request.POST.get('address', '')
            city = request.POST.get('city', '')
            state = request.POST.get('state', '')
            zip = request.POST.get('zip', '')
            phone_number = request.POST.get('phone_number', '')
            support = request.POST.get('support', '')
            agree = request.POST.get('agree', '')
            email_address = request.POST.get('email_address', '')
            number = request.POST.get('number', '')
            cvc = request.POST.get('cvc', '')
            exp = request.POST.get('exp', '')
            # token = form.cleaned_data['stripe_token'],
            # exp_m = int(request.POST.get('exp_month', ''))
            # exp_y = int(request.POST.get('exp_year', ''))

            exp_month = exp[0:2]
            exp_year = exp[5:9]

            subject = 'New Donation'
            from_email = settings.DEFAULT_FROM_EMAIL
            recipient_list = ['deniselarkins@/////\\\\\.com',
                              'charles@/////\\\\\.net',
                              'marcmunic@/////\\\\\.com',
                              ]

            token = stripe.Token.create(
                card={
                    'number': number,
                    'exp_month': exp_month,
                    'exp_year': exp_year,
                    'cvc': cvc
                },
            )

            customer = stripe.Customer.create(
                email=email_address,
                source=token,
            )

            total_support = decimal.Decimal(support) / 100
            total_charge = decimal.Decimal(int(support)) / 100

            # Charge the user's card:
            charge = stripe.Charge.create(
                amount=total_charge,
                currency='usd',
                description='Donation',
                customer=customer.id
            )

            ctx = {
                'name': name,
                'address': address,
                'city': city,
                'state': state,
                'zip': zip,
                'phone_number': phone_number,
                'email_address': email_address,
                'agree': agree,
                'charge': charge,
                'customer': customer,
                'total_support': total_support,
                'total_charge': total_charge
            }

            message = get_template('email_forms/direct_donation_form_email.html').render(Context(ctx))
            msg = EmailMessage(subject, message, from_email=from_email, to=recipient_list)
            msg.content_subtype = 'html'
            msg.send(fail_silently=True)

            return redirect(
                '/contribute/donation-support-thank-you/?name=' + name +
                '&address=' + address +
                '&state=' + state +
                '&city=' + city +
                '&zip=' + zip +
                '&phone_number=' + phone_number +
                '&email_address=' + email_address +
                '&total_support=' + str(total_support) +
                '&total_charge=' + str(total_charge)
            )
    context = {
        'title': 'Donation Pledge',
    }

    return render(request, 'contribute/_donation-application.html', context)
trans by 2020-08-10T14:29:07Z

python-为什么Django抛出错误“ /的DisallowedHost”?

我正在使用此Digital Ocean教程设置自己的Django服务器。 我按照每个步骤创建了Django框架,并使用以下命令运行服务器:

./manage.py runserver 0.0.0.0:8000

当我尝试访问端口8000上的IP时,显示以下错误:

DisallowedHost at /
Invalid HTTP_HOST header: 'XXX.XXX.XXX.XXX:8000'. You may need to add u'XXX.XXX.XXX.XXX' to ALLOWED_HOSTS.

(用X代替IP)

为什么会这样呢?

trans by 2020-08-10T11:43:06Z

我如何在django shell中打印设置的内容?

当我运行python manage.py shell时,我可以打印出python路径

>>> import sys
>>> sys.path

我应该键入什么来检查所有django设置?

trans by 2020-08-10T04:51:17Z

带有Django上传表单的空Request.FILES

尝试使用非常简单的形式将文件上传到新的类实例中。 我希望两个文件都在request.FILES中,但是它是空的。 我在捆绑的开发服务器上。

被困在这里,并经历了所有相关问题。

wayfinder_map.media_file = request.FILES['media_file'] 

产生

MultiValueDictKeyError:“在MultiValueDict中找不到密钥'media_file': {}>”

模型

class WayfinderMap(models.Model):
    """ Way-finding Map Config"""


    media_file = models.FileField(upload_to="maps", null=True, blank=True) 
    wall_file = models.FileField(upload_to="maps_data", null=True, blank=True) 

视图

@login_required
def create_map(request, form_class=WayfinderMapForm, template_name="wayfinder/map/create.html"):
wayfinder_map_form = form_class(request.user, request.POST or None, request.FILES)

    if wayfinder_map_form.is_valid():
        wayfinder_map = wayfinder_map_form.save(commit=False)
        wayfinder_map.media_file = request.FILES['media_file']
        wayfinder_map.data_file = request.FILES['data_file']
        wayfinder_map.creator = request.user
        wayfinder_map.save()
    return HttpResponseRedirect(wayfinder_map.get_absolute_url())

return render_to_response(template_name, {
    "wayfinder_map_form": wayfinder_map_form,
}, context_instance=RequestContext(request))

模板

<form enctype="multipart/form-data" class="uniForm" id="wayfinder_map_form" method="POST" action="">
        <fieldset class="inlineLabels">
            {{ wayfinder_map_form|as_uni_form }}
            <div class="form_block">
                <input type="hidden" name="action" value="create" />
                <input type="submit" value="{% trans 'create' %}"/>
            </div>
        </fieldset>
    </form>
trans by 2020-08-09T23:16:52Z

Python Django全局变量

我正在Django中寻找一种简单但推荐的方式,将变量仅存储在内存中。 当Apache重新启动或Django开发服务器重新启动时,该变量重置为0。更具体地说,我想计算在每个模型实例(数据库记录)上执行特定操作的次数,但是出于性能原因,我不这样做 想要将这些计数存储在数据库中。 我不在乎服务器重启后计数是否消失。 但是只要服务器启动,我就希望这些计数在Django Shell和Web界面之间保持一致,并且我希望能够返回对每个模型实例执行了多少次操作。

我不希望变量与用户或会话相关联,因为我可能想在不登录的情况下返回这些计数(并且无论任何用户登录,我都希望计数保持一致)。 我在描述全局变量吗? 如果是这样,如何在Django中使用一个? 我注意到urls.py,settings.py和models.py之类的文件似乎在每次服务器启动时仅被解析一次(与之相反,views.py似乎在每次请求时都会被解析)。 这是否意味着我应该在其中一个文件中声明变量? 还是应该以某种方式将其存储在模型属性中(只要它在服务器运行期间一直存在)? 这可能是一个简单的问题,但是我不确定在Django中是如何完成的。

任何意见或建议,不胜感激。谢谢,乔

trans by 2020-08-09T03:47:22Z

Django:没有这样的表:django_session

我已经找到了多个与此标题相关的主题,但是它们的解决方案都不适用于我。 我的服务器上有两个Django站点,都是通过Apache在我的Nginx前端提供的两个端口上使用不同的虚拟主机(用于静态文件)运行的。 一个站点使用MySql并可以正常运行。 另一个使用Sqlite3并获取标题中的错误。

我下载了sqlite.exe的副本,并查看了mysite.sqlite3(此目录中的SQLite数据库)文件,确实存在一个包含有效数据的django_session表。 我的system32中有sqlite.exe,Python路径中有site-packages文件夹。

这是我的settings.py文件的一部分:

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mysite.sqlite3',         # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

我确实使用了python manage.py syncdb,没有错误,只是一个“ No Fixtures”注释。

有谁知道这里可能还会发生什么? 我正在考虑仅将所有内容转移到我的老朋友MySql上,而忽略Sqlite,因为实际上它总是给我带来一些麻烦。 我只是为了知道它而使用它。 我没有绝对的理由要使用它。 但是,再次出于我的兴趣,有人知道这个问题是什么吗? 我不喜欢放弃

trans by 2020-08-09T02:40:53Z

django-Nginx uwsgi(104:对等连接重置),同时从上游读取响应头

环境是Nginx + uwsgi。

在某些GET请求中,从Nginx获取502错误的网关错误。 似乎与URL的长度有关。 在我们的特定情况下,这是一长串GET参数。 缩短GET参数,没有502错误。

从nginx / error.log

[error] 22113#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.100, server: server.domain.com, request: "GET <long_url_here>"

uwsgi错误日志中没有信息。

trans by 2020-08-09T00:53:49Z

我如何使用字符串作为关键字参数?

具体来说,我正在尝试使用一个字符串任意过滤ORM。 我已经尝试过exec和eval解决方案,但是我遇到了麻烦。 下面的代码不起作用,但这是我知道如何解释我要去的地方的最好方法

from gblocks.models import Image
f = 'image__endswith="jpg"' # Would be scripted in another area, but passed as text <user input>
d = Image.objects.filter(f)


#for the non-django pythonistas:
d = Image.objects.filter(image__endswith="jpg")
# would be the non-dynamic equivalent.
trans by 2020-08-09T00:52:07Z

如何在Django中为同一个模型提供两个外键?

我想要两个相同模型的外键:

class Test(models.model):
    example1 = models.ForeignKey(Example)
    example2 = models.ForeignKey(Example)

我收到如下错误:

字段“ example1”的访问器与相关的冲突 字段“ Example.test_set”。 添加related_name参数 到“ example1”的定义。

trans by 2020-08-08T23:48:34Z

python-添加自定义Django模型验证

我有一个带有开始和结束日期范围的Django模型。 我想强制执行验证,以便没有两个记录具有重叠的日期范围。 最简单的实现方法是什么,这样我就不必重复编写逻辑了?

例如 我不想在Form和ModelForm和admin表单以及模型的save()中重新实现此逻辑。

据我所知,Django在全球范围内强制执行这些类型的条件并不容易。

谷歌搜索并不是很有帮助,因为“模型验证”通常是指验证特定的模型字段,而不是验证整个模型内容或字段之间的关系。

trans by 2020-08-08T22:10:39Z

python-django witih sqlite3中的“ SQL变量太多”错误

我在Django中使用sqlite3遇到此错误:

异常值:SQL变量过多

我认为从这里开始的答案是这样的:

许多SQL程序员都熟悉使用问号(“?”)作为主机 参数。 SQLite还支持以“:”,“ $”或“。”开头的命名主机参数。 “ @”和带编号的主机参数,格式为“?123”。

为防止过多的内存分配,主机参数的最大值 数字为SQLITE_MAX_VARIABLE_NUMBER,默认为999。”

但是,还有一个我不明白的奇怪之处,那就是在django shell会话中(从views.py启动),相同的查询运行良好,但是从我的[:996]进行调用时,该查询无法运行。

这些是导致错误的代码行:

vals = Company.objects.filter(id__in=comp_ids).values('id', 'name').order_by('name')
names_map = SortedDict(vals)

其中views.py是包含1038个整数元素的集合。

完全相同的查询,甚至更大。 views.py(3800+)的运行状况良好django shell(以[:996]启动)-字典获取创建,我可以遍历它。

我尝试将views.py分解为若干组,例如 [:996](这似乎是限制,然后将其倒入),即filter(id__in=comp_ids[:996]),然后其余下一次迭代,这与“主机参数数量”一致说明。

但是,为什么它不能在django shell中工作,而不能在views.py中工作呢?

编辑:更多信息:在sqli中输入查询te shell(manage.py dbshell)返回完整的与django shell(manage.py shell)相同的没有错误的结果集。

这是参数(1039个元素)和查询的准确列表,如果您愿意的话想知道细节:

参数

(2, 3, 4, 2053, 6, 7, 2732, 10, 3737, 13, 2063, 2064, 17, 18, 21, 2393, 2052, 29, 30, 32, 2456, 35, 36, 38, 40, 2396, 42, 2731, 45, 46, 2095, 3343, 49, 2098, 2252, 53, 54, 58, 59, 2058, 62, 63, 64, 66, 67, 72, 2123, 3426, 3344, 79, 80, 81, 85, 2134, 87, 91, 92, 95, 98, 2747, 2149, 102, 104, 106, 2155, 109, 110, 3773, 2455, 2165, 118, 122, 2171, 2172, 127, 134, 135, 137, 138, 2187, 2413, 145, 148, 2414, 2198, 2199, 152, 153, 154, 2204, 157, 2210, 163, 2417, 169, 170, 2219, 172, 173, 3279, 2077, 179, 180, 181, 2230, 2231, 184, 186, 187, 2237, 190, 191, 2240, 2241, 3787, 2245, 2246, 2247, 2248, 2249, 2251, 204, 205, 207, 208, 209, 210, 213, 214, 2263, 2265, 3450, 222, 2273, 2274, 2275, 228, 2277, 2811, 231, 234, 2283, 2284, 238, 240, 243, 248, 250, 2299, 2300, 254, 2303, 2305, 258, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 267, 269, 2318, 271, 2320, 2321, 2322, 2323, 2325, 278, 2327, 280, 282, 283, 285, 286, 287, 290, 2342, 295, 298, 2347, 2348, 2349, 2350, 2351, 304, 2353, 307, 309, 312, 318, 320, 321, 323, 326, 327, 328, 332, 333, 334, 2385, 338, 2387, 2388, 2389, 2390, 2391, 2392, 345, 2394, 347, 348, 350, 352, 354, 355, 356, 357, 359, 360, 2410, 364, 365, 366, 2415, 2416, 369, 2451, 373, 2422, 375, 377, 2426, 2428, 2429, 2430, 2432, 2433, 387, 2454, 391, 2441, 2443, 398, 399, 400, 401, 2553, 403, 404, 405, 406, 407, 408, 409, 410, 411, 413, 2462, 3628, 418, 2459, 420, 2469, 2470, 2472, 425, 427, 2476, 2461, 2483, 2485, 440, 441, 2490, 443, 444, 445, 446, 2496, 2497, 2499, 2501, 2502, 455, 2504, 2505, 459, 460, 2466, 2510, 463, 465, 466, 467, 469, 470, 2519, 2520, 2468, 474, 2529, 2531, 484, 486, 487, 488, 490, 491, 493, 2542, 2543, 2544, 497, 498, 499, 500, 2549, 502, 2551, 504, 505, 2554, 2555, 2556, 509, 2558, 511, 2560, 2562, 2475, 2564, 517, 2566, 2567, 2568, 2569, 523, 2572, 526, 527, 529, 536, 538, 539, 2588, 2589, 2590, 2596, 550, 552, 556, 2605, 2607, 2608, 2612, 565, 566, 567, 568, 580, 2634, 587, 2636, 2638, 2639, 2270, 595, 598, 2489, 605, 606, 609, 610, 2407, 615, 618, 619, 620, 2669, 2670, 2493, 2672, 2152, 628, 629, 630, 2680, 2682, 2684, 640, 641, 642, 2691, 645, 648, 650, 2699, 2700, 2701, 2702, 2703, 2705, 659, 2708, 661, 2712, 667, 2718, 2719, 2720, 2721, 2723, 2724, 2725, 2728, 681, 2730, 2614, 684, 2733, 2735, 2736, 689, 2739, 2741, 2746, 699, 701, 706, 707, 2757, 2759, 2760, 2508, 2763, 2766, 721, 2771, 725, 730, 2511, 732, 2170, 734, 2343, 743, 749, 2798, 2799, 752, 753, 2515, 756, 2078, 2807, 2808, 2412, 763, 2813, 766, 769, 2818, 2821, 2822, 779, 2861, 2833, 2834, 2835, 2836, 2837, 790, 802, 2852, 2854, 2856, 2550, 810, 2860, 813, 2862, 2863, 817, 2869, 2870, 2871, 824, 826, 2876, 829, 830, 2882, 836, 2885, 2886, 3574, 2890, 2892, 2893, 847, 2896, 2872, 2899, 2902, 2546, 2909, 2256, 2912, 2913, 870, 2920, 2921, 2922, 876, 2930, 887, 2937, 3903, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 903, 904, 905, 906, 907, 908, 909, 910, 911, 2884, 2970, 927, 2977, 2978, 2979, 2980, 2981, 2545, 941, 942, 2205, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 3014, 967, 968, 969, 970, 971, 3234, 2552, 980, 981, 982, 983, 985, 2895, 3038, 995, 996, 998, 2897, 2538, 2761, 3051, 1012, 1013, 3062, 3063, 3066, 2559, 3073, 1027, 1028, 1029, 1030, 2421, 3080, 1036, 1038, 1039, 1040, 1041, 3092, 3246, 3853, 1050, 3099, 1057, 3109, 3112, 1067, 1068, 1073, 1074, 1075, 1076, 1078, 1081, 2491, 1086, 2229, 1088, 1089, 1090, 1091, 1092, 1093, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 3161, 1119, 3170, 2235, 3174, 3176, 3177, 1132, 1133, 1134, 1135, 1136, 3186, 1141, 3192, 3193, 3194, 3195, 3197, 3198, 2425, 1152, 1155, 1156, 3205, 2924, 3214, 1168, 1169, 1171, 1172, 1173, 1174, 1175, 1176, 3225, 1178, 3230, 1186, 1189, 1193, 1194, 1195, 1196, 3245, 1198, 1199, 1200, 1202, 2541, 3273, 1210, 3259, 1213, 1225, 1226, 1228, 1230, 2253, 3280, 3281, 1234, 1235, 1238, 1243, 1244, 1248, 1249, 3298, 3299, 1253, 3302, 2257, 3304, 3305, 3306, 3308, 1262, 2838, 3315, 3317, 3381, 1277, 1278, 3327, 3331, 3332, 1285, 2945, 1288, 1289, 1292, 1295, 1296, 1298, 3347, 3348, 3349, 1302, 3351, 3352, 3353, 1306, 1307, 3356, 1312, 3364, 1320, 3370, 3371, 3372, 3374, 3375, 1328, 3377, 3378, 3380, 1333, 1334, 3388, 3390, 3296, 3394, 3395, 2227, 1350, 2615, 1357, 1361, 1362, 3411, 3412, 3413, 1368, 2276, 1371, 1372, 3105, 1378, 2228, 3428, 3430, 3433, 1400, 1402, 1404, 3453, 3455, 3808, 1409, 3458, 3459, 1412, 1414, 1416, 1417, 1418, 1419, 1420, 2093, 3470, 1437, 3486, 1439, 2571, 3491, 3492, 3493, 1446, 2435, 1454, 1463, 3663, 3523, 1477, 1478, 1479, 1480, 1481, 1482, 3531, 1484, 1488, 1489, 1490, 3540, 1494, 1495, 1496, 3546, 3547, 2298, 1510, 1512, 3666, 1520, 1523, 2302, 1526, 1527, 3584, 1539, 1540, 1542, 1543, 1548, 1549, 3393, 1554, 1555, 1560, 1561, 3079, 1565, 2507, 3616, 3617, 1570, 3619, 3620, 3621, 3622, 1575, 3624, 2817, 3629, 3630, 1583, 1590, 1591, 1592, 2996, 3643, 3645, 2997, 3649, 2781, 3653, 3655, 1608, 3657, 2317, 1618, 3667, 1620, 3669, 1625, 2319, 3002, 2782, 1633, 1634, 3199, 3691, 3346, 3688, 1650, 1656, 3007, 3709, 3008, 1666, 2616, 3009, 2668, 2306, 3723, 3010, 2238, 1681, 1682, 1683, 1687, 3012, 3738, 2671, 1693, 3013, 1697, 1698, 2548, 3749, 3755, 3757, 3758, 2333, 1714, 1718, 3770, 3018, 1729, 3778, 3783, 1739, 1744, 3793, 1746, 1752, 1753, 1755, 3741, 3707, 1771, 1774, 2514, 1779, 2494, 3831, 1788, 2346, 3029, 3840, 3182, 2689, 1802, 1803, 2690, 1811, 1815, 1817, 3011, 2352, 1827, 2467, 1832, 3881, 1839, 1840, 2107, 1848, 1849, 2698, 2653, 1855, 1857, 1864, 1867, 1872, 1873, 3923, 1878, 1882, 1889, 3354, 1903, 1904, 2366, 1915, 1920, 1921, 1927, 1928, 1930, 1931, 3133, 1943, 1947, 1957, 1958, 1959, 1964, 1967, 1968, 1976, 2809, 3612, 1987, 1988, 1989, 3745, 1994, 2000, 2003, 2382, 2008, 3613, 2021, 2022, 3410, 3464, 2033, 2034, 2037, 2038, 2729, 2044)

询问

'SELECT "screen_company"."id", "screen_company"."name" FROM "screen_company" WHERE "screen_company"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?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?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ORDER BY "screen_company"."name" ASC'

(顺便说一句,您不需要为此使用pdb-django非常有帮助发生错误时在浏览器中显示回溯(在render_to_response()?中),并带有每个步骤的局部变量的完整列表,因此您可以看到完整的查询那里。)

但是,我之前曾尝试使用pdb进入django代码,并且发现错误实际上源自python的pysqlite2.dbapi2(或sqlite3.dbapi2)模块,位于django / db / backends / sqlite3 / base.py的第200行:

return Database.Cursor.execute(self, query, params)

(这也在错误页面中显示的有用回溯中),其中数据库是pysqlite2.dbapi2或sqlite3.dbapi2的别名,具体取决于在您的python版本上。

但是我认为调用堆栈太低了,无法继续调试(目前),因此决定停下来,并开始考虑变通方法和谷歌搜索答案代替。 :)

trans by 2020-08-08T21:34:15Z

django-如何在Python中将datetime.timedelta转换为分钟和小时?

我得到这样的开始日期:

from django.utils.timezone import utc
import datetime

start_date = datetime.datetime.utcnow().replace(tzinfo=utc)
end_date = datetime.datetime.utcnow().replace(tzinfo=utc)
duration = end_date - start_date

我得到这样的输出:

datetime.timedelta(0, 5, 41038)

如何将其转换为正常时间,如下所示?

10分钟1个小时是这样的

trans by 2020-08-07T06:12:21Z

django-使用内联表单集创建模型和相关模型

[我已经在Django用户上发布了此| Google网上论坛也可以。]

使用内联表单集文档中的示例,我能够编辑属于特定模型的对象(使用模型形式)。 我一直在尝试遵循相同的模式使用内联表单集创建新对象,但是无法为此我要打扫头脑,以展现出可行的观点。

使用与上面的链接相同的示例,我将如何处理创建一个“作者”模型的新实例及其相关的实例“书”对象?

trans by 2020-08-06T22:56:16Z

Django:Rest Framework认证负责人

我正在使用Django REST API,尝试对我的请求进行身份验证。

这是我要发送的:

Content-Type: application/json, Authentication: token="6d82549b48a8b079f618ee9c51a6dfb59c7e2196"

这就是我得到的:

{"detail": "Authentication credentials were not provided."}

有人可以给我正确的标题吗?

谢谢

标题:

Accept: application/json
Content-Type: application/json
Authorization: Token 6d82549b48a8b079f618ee9c51a6dfb59c7e2196
Connection: keep-alive
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17

enter image description here

Settings.py

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.permissions.IsAdminUser',


    ),
    'PAGINATE_BY': 10
}

view.py

class ProfileList(generics.ListCreateAPIView):
    """
    API endpoint that represents a list of users.
    """
    permission_classes = (permissions.IsAuthenticated,)
    model = Profile
    serializer_class = ProfileSerializer

    def pre_save(self, obj):
        obj.owner = self.request.user
trans by 2020-08-06T18:44:43Z

python-Django DetailView-如何在get_context_d中使用'request'

我试图修改上下文数据,所以我覆盖了get_context_data。我需要request变量来修改此上下文。 那么如何在get_context-data中获取request变量?

trans by 2020-08-06T09:57:00Z

python-如何使Django应用程序中的Facebook登录成为可能?

我已经创建了一个Django应用程序。 该应用程序具有登录功能。

有人可以帮忙找到一种方法,使使用Facebook凭据登录或向我提供一些实现它的教程吗?

trans by 2020-08-05T16:08:52Z

django-Vagrant + Chef:设置错误“ Chef所需的共享文件夹在虚拟机上丢失”。

我已经使用Chef(+ library Chef)安装了Vagrant + Virtualbox。 当我第一次执行vagrant reload --provision时,食谱会正确加载。 但是,当我事后进行配置时(无论是2997966317417497615361、vagrant reload --provision还是vagrant up --provision,我都会收到此错误:

Shared folders that Chef requires are missing on the virtual machine.
This is usually due to configuration changing after already booting the
machine. The fix is to run a `vagrant reload` so that the proper shared
folders will be prepared and mounted on the VM.

我到处搜索,给出的唯一解决方案是做2997966317417497615360,这一工作达到了Vagrant 1.3.1。

trans by 2020-08-05T12:27:07Z

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 下一页 共73页