Sam*_*Sam 6 django django-models python-3.x
所以我是 django 的新手,我正在努力打造一个小市场。我做了一个产品应用程序。这是内部代码:这是用于views.py:
from django.shortcuts import render
from django.http import HttpResponse
from products.models import product
def index(request):
  Products = product.objects.all()
  return render(request, 'index.html', {'products': Products})
def new(request):
  return HttpResponse('New Product')
这是用于models.py:
from django.db import models
class product(models.Model):
  name = models.CharField(max_length=150)
  price = models.FloatField()
  stock = models.IntegerField()
  image_url = models.CharField(max_length=2083)
我还制作了一个模板文件夹并将其放入其中进行实验:
<h1>Products</h1>
<ul>
  {% for product in Products %}
    <li>{{ product.name }}</li>
  {% endfor %}
</ul>
以及其他一些常用代码。但我在这部分收到一个pylint错误:
<h1>Products</h1>
<ul>
  {% for product in Products %}
    <li>{{ product.name }}</li>
  {% endfor %}
</ul>
请帮我!谢谢
PRA*_*PUT 17
试试这个 Use pylint --generated-members=objects
安装 Django pylint:
pip install pylint-django
ctrl+shift+p > 首选项:配置特定于语言的设置 > Python
可用于 Python 语言的 settings.json 应如下所示:
{
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django"
    ],
    "[python]": {
    }
}
| 归档时间: | 
 | 
| 查看次数: | 6054 次 | 
| 最近记录: |