编程语言
首页 > 编程语言> > 启动Django程序报:SyntaxError: Non-ASCII character ‘\xe6‘ in file C:\Users\libol\PycharmProjects\Djan

启动Django程序报:SyntaxError: Non-ASCII character ‘\xe6‘ in file C:\Users\libol\PycharmProjects\Djan

作者:互联网

报错截图:

image-20210728154521205

根据提示,了解到是models.py文件Non-ASCII问题。

models.py文件如下:

from django.db import models
from django.contrib.auth.models import User

from django.utils.translation import gettext_lazy as _

JobTypes = [
    (0, "技术类"),
    (1, "产品类"),
    (2, "运营类"),
    (3, "设计类"),
    (4, "市场营销类")
]

Cities = [
    (0, "北京"),
    (1, "上海"),
    (2, "深圳"),
    (3, "杭州"),
    (4, "广州")
]


class Job(models.Model):
    # Translators: 职位实体的翻译
    job_type = models.SmallIntegerField(blank=False, choices=JobTypes, verbose_name=_("职位类别"))
    job_name = models.CharField(max_length=250, blank=False, verbose_name=_("职位名称"))
    job_city = models.SmallIntegerField(choices=Cities, blank=False, verbose_name=_("工作地点"))
    job_responsibility = models.TextField(max_length=1024, verbose_name=_("职位职责"))
    job_requirement = models.TextField(max_length=1024, blank=False, verbose_name=_("职位要求"))
    creator = models.ForeignKey(User, verbose_name=_("创建人"), null=True, on_delete=models.SET_NULL)
    created_date = models.DateTimeField(verbose_name=_("创建日期"), auto_now_add=True)
    modified_date = models.DateTimeField(verbose_name=_("修改日期"), auto_now=True)

解决办法:

在models.py文件开头加

# -*- coding: utf-8 -*-

加上之后,成功运行。

image-20210728154808886

解决!!!

标签:Non,False,verbose,models,name,job,blank,Django,Users
来源: https://blog.csdn.net/qq_37924905/article/details/119182212