启动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

根据提示,了解到是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 -*-

加上之后,成功运行。

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

解决!!!

上一篇:Redis如何实现高并发分布式锁?


下一篇:2021-7-25 Two Substrings