Go教程

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

解决!!!

这篇关于启动Django程序报:SyntaxError: Non-ASCII character ‘\xe6‘ in file C:\Users\libol\PycharmProjects\Djan的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!