小编Asa*_*hel的帖子

Django 3.2 AttributeError: 'TextField' 对象没有属性 'db_collat​​ion'

我在 Django 3.1 上有一个现有项目,并将我的项目升级到 Django 3.2。我在我的项目中创建了一个名为支付的应用程序。但是当我进行迁移时。它犯了一个错误 AttributeError: 'TextField' object has no attribute 'db_collation'

from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _
# Create your models here.
from simple_history.models import HistoricalRecords


class TransactionType(models.TextChoices):
    CASH_IN = 'IN', _('Cash In')
    CASH_OUT = 'OUT', _('Cash Out')


class TransactionMethod(models.TextChoices):
    STUDENT_TR = 'STT', _('Student Transaction')
    BANK_TR = 'BKT', _('Bank Transaction')
    SCHOOL_TR = 'SLT', _('School Transaction')
    Teacher_TR = 'TRT', _('Teacher Transaction')
    DONATE_TR = 'DET', _('Donate Transaction')


class Payment(models.Model):
    id = models.AutoField(primary_key=True) …
Run Code Online (Sandbox Code Playgroud)

python django django-models

8
推荐指数
3
解决办法
1069
查看次数

Flask 运行问题:socket.error:[Errno 98] 地址已在使用中

如果我在 sublime text 或 PyCharm 中运行 Flask,我收到此错误消息sublime issue ( My OS: Ubuntu 16.04) "socket.error: [Errno 98] Address already in use"。但是如果我在我的 Ubuntu终端上运行 Flask ,它正在运行。我知道该端口使用了另一项服务。然后我试图从 google/stackoverflow 解决这个问题。

# ps ax | grep 5000 // or # ps ax | grep name_of_service

# kill 3750            // or # killall name_of_service
Run Code Online (Sandbox Code Playgroud)

但什么都没有改变。只有当我尝试在 sublime 或 pycharm IDE 上运行时才发现这个问题。

python sockets flask flask-login sublimetext3

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

UnicodeDecodeError:Django使用weasyprint生成PDF

我正在用Django开发应用程序。浏览选择链接时,我想生成pdf。所以我用weasyprint模块来转换我的pdf。我导入了weasyprint模块。但是,当我运行该应用程序时,发现了一些错误。这是views.py文件

def customersProfile(request, customer_id, sys_type):
    sys_type=sys_type
    area="profile"
    site_credit = site_credit1
    time_now=timezone.now()
    customers=get_object_or_404(CustomerInfo, pk=customer_id)

    html_string = render_to_string('shop/profile.html', {'customers': customers, 'todaydate': today_date,'site_name': 'Moon Telecom', 'time_now': time_now, 'site_credit': site_credit, 'area': area})
    html = HTML(string=html_string)
    result = html.write_pdf()


    response = HttpResponse(content_type='application/pdf;')
    response['Content-Disposition'] = 'inline; filename=list_people.pdf'
    response['Content-Transfer-Encoding'] = 'binary'
    with tempfile.NamedTemporaryFile(delete=True) as output:
        output.write(result)
        output.flush()
        output = open(output.name, 'r')
        response.write(output.read())

    return response
Run Code Online (Sandbox Code Playgroud)

这是HTML文件。我想创建pdf这个html文件。

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head> …
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-models weasyprint

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

nil check left 和 right 之间有什么区别

该函数接受两个字符串并返回 struct 或 nil,我在该函数内编写了一个 struct 仅供该函数使用。

\n
type OrgFundingsDetailsFCT struct {\n    ID           int     `db:"id"`\n    OrgProfileID int     `db:"org_profile_id"`\n    OrgID        int     `db:"org_id"`\n    RefID        string  `db:"ref_id"`\n    AmountUSD    float64 `db:"amount_usd"`\n    FundingDate  string  `db:"funding_date"`\n    Status       string  `db:"status"`\n    Round        string  `db:"round"`\n    CreatedBy    string  `db:"created_by"`\n}\n
Run Code Online (Sandbox Code Playgroud)\n
func (s *Server) getCompareOrgFundingsByRefID(refID, status string) (*OrgFundingsDetailsFCT, error) {\n    type orgFunding struct {\n        RefID  string `db:"ref_id"`\n        Status string `db:"status"`\n    }\n\n    var orgFundingsDetailsFCT OrgFundingsDetailsFCT\n\n    orgfunding := orgFunding{\n        RefID:  refID,\n        Status: status,\n    }\n\n    const query = `SELECT id,\n                    org_profile_id,\n                    org_id,\n                    ref_id,\n                    amount_usd,\n                    funding_date,\n …
Run Code Online (Sandbox Code Playgroud)

comparison null go

-1
推荐指数
1
解决办法
346
查看次数