django如何将mysql中表的内容通过models.py在网页端显示

各位朋友们好,mysql数据库中有1张表student包含了name,age两个字段,共1000条数据,现在我想通过django在网页端展示这些数据。看了网上的教程,我在models.py中添加了:
from django.db import models
import MySQLdb
import mysite.settings
class student(models.Model):
name = models.CharField(max_length = 20)
age = models.CharField(max_length = 20)

def __str__(self):
    return self.name

并且在views.py中编写以下代码:

- coding: utf-8 -

import sys
reload(sys)
sys.setdefaultencoding("utf-8")

from django.shortcuts import render, render_to_response
from polls.models import student
from django.http import HttpResponse
import MySQLdb
import mysite.settings

def index(request):
students = student.objects.all()
name = ""
for stud in students:
name = stud.name
break
return render_to_response('index.html' , {'students':students , 'name':name})
在settings.py中设置数据库如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
#'NAME': os.path.join(BASE_DIR, 'test'),#database name
'NAME': 'test',
'USER':'root',
'PASSWORD':'123456',
'HOST': 'localhost',
'PORT': '3306',
}
}
在网页端index.html中编写以下内容

 <body>
    <p>学生数据如下:</p>
    <table border="10">
        {% for student in students %}
            <tr >
                <td>{{student.name}}</td>
                <td>{{student.age}}</td>
            </tr>
        {% endfor %}
    </table>
</body>

我执行了python manage.py makemigrations 和 python manage.py migrate,虽然也出现了与mysql中表student对应的blog_student表,但是blog_student中没有内容,而且网页端没有数据显示。
请教各位朋友们,这是什么原因呢?该如何显示数据啊?
希望朋友们能指点一下,万分感谢。

3个回答

qingyuanluofeng
天地一扁舟 朋友,您好,非常感谢您的回答。我把问题再和您讲一下吧:项目是这样的有程序会读取学生数据并放入mysql学生表student中,现在我想通过django展示学生数据。但是按照网上的教程,在models.py中创建student的模型,并执行了python manage.py migrate,并在views.py中用student.objects.all()获取的数据传给网页端用{% for student in students %}…. 进行展示,但是没有出现数据,查到的数据为空。 django生成了对应的模型表blog_student,但里面没有数据,我之前的mysql中的student表中是有数据的,想请问您,django展示的数据到底来自于哪里?是blog_student吗,还是说利用blog_student去管理student表,展示的是student表中的内容。 希望朋友能指点我一下,十分感谢。
4 年多之前 回复

不显示出来是必然的,因为你在models.py中创建的数据模型对应的是blog_student 这个表,但是你的学生数据在student这个表中,所以读不出来。
想要读出来的方法:
1.可以将student表中的数据导入到blog_student中;
2.不用models.py去创建数据模型了,直接在view.py中去连接数据库,然后读取student表中的数据。

先要分析一下,你的数据库表是如何创建的,数据是否成功传递给后端,然后就是数据格式是否跟数据库匹配,这样才能插入数据库

qingyuanluofeng
天地一扁舟 朋友,您好,非常感谢您的回答。我把问题再和您讲一下吧:项目是这样的有程序会读取学生数据并放入mysql学生表student中,现在我想通过django展示学生数据。但是按照网上的教程,在models.py中创建student的模型,并执行了python manage.py migrate,并在views.py中用student.objects.all()获取的数据传给网页端用{% for student in students %}…. 进行展示,但是没有出现数据,查到的数据为空。 django生成了对应的模型表blog_student,但里面没有数据,我之前的mysql中的student表中是有数据的,想请问您,django展示的数据到底来自于哪里?是blog_student吗,还是说利用blog_student去管理student表,展示的是student表中的内容。 希望朋友能指点我一下,十分感谢。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于django执行python manage.py syncdb命令却缺少自己所需要建的models.py内的表
在django项目中的settings.py文件中的_app代码,数据库没问题,可以连接上,但是:python manage.py syncdb命令却无法生成自己models.py内所定义的实体类表。 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'west', ) models.py内的代码 from django.db import models class Employee(models.Model): name = models.CharField(max_length=200) 谁能帮我看看这是怎么回事,查了很多资料还是无法解决。
如何在django中使用mysql自带的MySQL Connector Python 8.0 for Python 3.7?
django连接mysql提示 django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? 也就是说要我pip install mysqlclient 可我安装mysql的时候自带MySQL Connector Python 8.0 for Python 3.7 C:\Program Files\MySQL\MySQL Connector Python 8.0 for Python 3.7 也就是说我只要告诉django连接mysql用这个目录里的文件就好了... 可我怎么才能让django知道这件事...
django中创建表python manage.py makemigrations出现以下错误 ,望大神指导
![图片说明](https://img-ask.csdn.net/up load/201812/05/1544007099_480215.jpg) ![图片说明](https://img-ask.csdn.net/upload/201812/05/1544012043_872565.jpg) C:\Users\Administrator\PycharmProjects\mysite>python manage.py makemigrations Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 216, in ensure_connection self.connect() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 194, in connect self.connection = self.get_new_connection(conn_params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\mysql\base.py", line 227, in get_new_connection return Database.connect(**conn_params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\__init__. py", line 94, in Connect return Connection(*args, **kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 327, in __init__ self.connect() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 598, in connect self._request_authentication() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 873, in _request_authentication auth_packet = _auth.caching_sha2_password_auth(self, auth_packet) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\_auth.py" , line 253, in caching_sha2_password_auth pkt = _roundtrip(conn, data) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\_auth.py" , line 112, in _roundtrip pkt = conn._read_packet() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 683, in _read_packet packet.check_error() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\protocol. py", line 220, in check_error err.raise_mysql_exception(self._data) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\__init__.py", line 381, in execute_from_command_line utility.execute() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\base.py", line 353, in execute output = self.handle(*args, **options) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\manag ement\commands\makemigrations.py", line 103, in handle loader.check_consistent_history(connection) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrati ons\loader.py", line 281, in check_consistent_history applied = recorder.applied_migrations() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrati ons\recorder.py", line 61, in applied_migrations if self.has_table(): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrati ons\recorder.py", line 44, in has_table return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cur sor()) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 255, in cursor return self._cursor() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 232, in _cursor self.ensure_connection() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 216, in ensure_connection self.connect() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.p y", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 216, in ensure_connection self.connect() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\base\base.py", line 194, in connect self.connection = self.get_new_connection(conn_params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backend s\mysql\base.py", line 227, in get_new_connection return Database.connect(**conn_params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\__init__. py", line 94, in Connect return Connection(*args, **kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 327, in __init__ self.connect() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 598, in connect self._request_authentication() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 873, in _request_authentication auth_packet = _auth.caching_sha2_password_auth(self, auth_packet) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\_auth.py" , line 253, in caching_sha2_password_auth pkt = _roundtrip(conn, data) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\_auth.py" , line 112, in _roundtrip pkt = conn._read_packet() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\connectio ns.py", line 683, in _read_packet packet.check_error() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\protocol. py", line 220, in check_error err.raise_mysql_exception(self._data) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES) ")
执行 python manage.py makemigrations 提示错误
Traceback (most recent call last): File "manage.py", line 23, in <module> main() File "manage.py", line 19, in main execute_from_command_line(sys.argv) File "D:\codeProgram\python3.7\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line utility.execute() File "D:\codeProgram\python3.7\lib\site-packages\django\core\management\__init__.py", line 357, in execute django.setup() File "D:\codeProgram\python3.7\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "D:\codeProgram\python3.7\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "D:\codeProgram\python3.7\lib\site-packages\django\apps\config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "D:\codeProgram\python3.7\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "D:\codeStudy\django企业开发实战\typeidea\typeidea\blog\models.py", line 8, in <module> class Category(models.Model): File "D:\codeStudy\django企业开发实战\typeidea\typeidea\blog\models.py", line 20, in Category owner = models.ForeignKey(User, verbose_name="作者") TypeError: __init__() missing 1 required positional argument: 'on_delete' ``` # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.contrib.auth.models import User from django.db import models class Category(models.Model): STATUS_NORMAL = 1 STATUS_DELETE = 0 STATUS_ITEMS = ( (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), ) name = models.CharField(max_length=50, verbose_name="名称") status = models.PositiveIntegerField( default=STATUS_NORMAL, choices=STATUS_ITEMS, verbose_name="状态") is_nav = models.BooleanField(default=False, verbose_name="是否为导航") owner = models.ForeignKey(User, verbose_name="作者") created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") class Meta: verbose_name = verbose_name_plural = '分类' class Tag(models.Model): STATUS_NORMAL = 1 STATUS_DELETE = 0 STATUS_ITEMS = ( (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), ) name = models.CharField(max_length=10, verbose_name="名称") status = models.PositiveIntegerField( default=STATUS_NORMAL, choices=STATUS_ITEMS, verbose_name="状态") owner = models.ForeignKey(User, verbose_name="作者") created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") class Meta: verbose_name = verbose_name_plural = '标签' class Post(models.Model): STATUS_NORMAL = 1 STATUS_DELETE = 0 STATUS_DRAFT = 2 STATUS_ITEMS = ( (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), (STATUS_DRAFT, '草稿'), ) title = models.CharField(max_length=255, verbose_name="标题") desc = models.CharField(max_length=1024, blank=True, verbose_name="摘要") content = models.TextField(verbose_name="正文", help_text="正文必须为MarkDown格式") status = models.PositiveIntegerField( default=STATUS_NORMAL, choices=STATUS_ITEMS, verbose_name="状态") category = models.ForeignKey(Category, verbose_name="分类") tag = models.ManyToManyField(Tag, verbose_name="标签") owner = models.ForeignKey(User, verbose_name="作者") created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") class Meta: verbose_name = verbose_name_plural = "文章" ```
django.db.utils.InternalError: (1050, "Table 'django_content_type' already exists") 迁移文件建立数据表的时候一直报错
django.db.utils.InternalError: (1050, "Table 'django_content_type' already exists") 在网上看到很多的方法,大概都是 先删除 所有的迁移文件, 再删除 数据库中对应的 Django_migrations 表里面的所有数据 之后再进行创建迁移文件然后再执行创建数据表的操作,但是报 没有应用啥啥啥的错误。。。 接着执行: python manage.py migrate booktest --fake 结果再执行 : python manage.py migrate 还是报 1050 的错误。。。。。。。。 下面附上详细报错信息,求网友大哥们解答~~!! (django_py3) huangdonglin@huangdonglin-virtual-machine:~/django_show/test2$ python manage.py migrate Operations to perform: Synchronize unmigrated apps: messages, staticfiles Apply all migrations: admin, booktest, sessions, auth, contenttypes Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial...Traceback (most recent call last): File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 124, in execute return self.cursor.execute(query, args) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result result.read() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read first_packet = self.connection._read_packet() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1050, "Table 'django_content_type' already exists") The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 221, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/migrations/executor.py", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in apply_migration state = migration.apply(state, schema_editor) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/migrations/migration.py", line 115, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards schema_editor.create_model(model) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 286, in create_model self.execute(sql, params or None) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 111, in execute cursor.execute(sql, params) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/utils.py", line 97, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/utils/six.py", line 658, in reraise raise value.with_traceback(tb) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 124, in execute return self.cursor.execute(query, args) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result result.read() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read first_packet = self.connection._read_packet() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/home/huangdonglin/.virtualenvs/django_py3/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval)
Django执行python manage.py makemigrations 报错,数据库是postgresql,大神救救孩子
Traceback (most recent call last): File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 220, in ensure_connection self.connect() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 197, in connect self.connection = self.get_new_connection(conn_params) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\postgresql\base.py", line 185, in get_new_connection connection = Database.connect(**conn_params) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\psycopg2\__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\base.py", line 369, in execute output = self.handle(*args, **options) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle loader.check_consistent_history(connection) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\migrations\loader.py", line 283, in check_consistent_history applied = recorder.applied_migrations() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\migrations\recorder.py", line 76, in applied_migrations if self.has_table(): File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 260, in cursor return self._cursor() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 236, in _cursor self.ensure_connection() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 220, in ensure_connection self.connect() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 220, in ensure_connection self.connect() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\base\base.py", line 197, in connect self.connection = self.get_new_connection(conn_params) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\django\db\backends\postgresql\base.py", line 185, in get_new_connection connection = Database.connect(**conn_params) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\psycopg2\__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError
django 运行 python manage.py runserver 显示No module named 'tutorial.quickstart' 无法安装tutorial
python manage.py runserver django 运行 python manage.py runserver 显示 No module named 'tutorial.quickstart' 且无法安装tutorial
关于Django执行迁移文件时,ForeignKey里面加on_delete=models.CASCADE报错问题,谁知道时怎么回事?万分感谢!!
Django 在创建模型类后,执行一下代码迁移文件时,在ForeignKey里面不加on_delete=models.CASCADE会报错,加了后,其他又外键的模型类不报错,就这个报错。 ``` class GoodsType(BaseModel): """商品类型模型类""" name = models.CharField(max_length=20, verbose_name="种类名称") logo = models.CharField(max_length=20, verbose_name="标识") image = models.ImageField(upload_to="type", verbose_name="商品类型图片") class Mete: db_table = "df_goods_type" verbose_name = "商品种类" verbose_name_plural = verbose_name def __str__(self): return self.name class GoodsSKU(BaseModel): """商品SKU模型类""" status_choices = ( (0, "下线"), (1, "上线"), ) type = models.ForeignKey("GoodsType", on_delete=models.CASCADE, verbose_name="商品种类") goods = models.ForeignKey("Goods", on_delete=models.CASCADE, verbose_name="商品SPU") name = models.CharField(max_length=20, verbose_name="商品名称") desc = models.CharField(max_length=256, verbose_name="商品简介") price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="商品价格") unite = models.CharField(max_length=20, verbose_name="商品单位") image = models.ImageField(upload_to='goods', verbose_name="商品图片") stock = models.IntegerField(default=1, verbose_name="商品库存") sales = models.IntegerField(default=0, verbose_name="商品销量") status = models.SmallIntegerField(default=1, choices=status_choices,verbose_name="商品状态") class Meta: db_table = "df_goods_sku" verbose_name = "商品" verbose_name_plural = verbose_name class GoodImage(models): """商品图片模型类""" sku = models.ForeignKey("GoodsSKU", on_delete=models.CASCADE, verbose_name="商品") image = models.ImageField(upload_to="good", verbose_name="图片路径") class Meta: db_table = "df_goods_image" verbose_name = "商品图片" verbose_name_plural = verbose_name ``` 报错 ``` python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/u/.virtualenvs/dailyfresh/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/home/u/.virtualenvs/dailyfresh/lib/python3.5/site-packages/django/core/management/__init__.py", line 357, in execute django.setup() File "/home/u/.virtualenvs/dailyfresh/lib/python3.5/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/home/u/.virtualenvs/dailyfresh/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/home/u/.virtualenvs/dailyfresh/lib/python3.5/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 665, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/home/u/jeth/dailyfresh/apps/goods/models.py", line 56, in <module> class GoodImage(models): TypeError: module.__init__() takes at most 2 arguments (3 given) ```
django连接MySQL报错django.db.utils.OperationalError: (2006, <NULL>)?
最近想学django,于是照着Django官方文档一步步学,没想到刚到连接数据库,就卡了。 在pycharm上通过django连接MySQL报如图所示错误![图片说明](https://img-ask.csdn.net/upload/201908/25/1566734912_878477.png)![图片说明](https://img-ask.csdn.net/upload/201908/25/1566734921_243846.png)![图片说明](https://img-ask.csdn.net/upload/201908/25/1566734929_53248.png) 网上搜索,试了各种方法,包括改hosts文件和HOST改成127.0.0.1,都不成功。把下面这几行代码注释掉,换成原来的sqlite,就可以成功运行,实在不知道什么原因,请各位大佬帮忙看下怎么解决。 环境:Django2.2.1、MySql8.0 下面是我的setting.py文件。一开始pycharm也连不上Mysql,我改了他的时区,Asia/Shanghai,就可以了,但是Django怎么也连不上 ``` """ Django settings for webProject project. Generated by 'django-admin startproject' using Django 2.2.1. For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'uri0z)r@kn3p)l%6(9if)1$74kv9ag$p@zadp_p$ph_x0(v9h=' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'webProject.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')] , 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'webProject.wsgi.application' # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # } # } DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'webcrawler', 'USER': 'root', 'PASSWORD': '111111', 'HOST': 'localhost', 'PORT': '3306', } } # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' ```
django安装后使用 mange.py错误,求解
在ubuntu下安装了django 1.9, 使用manage.py时有报错:(python版本为2.7和3.4) 比如./manage.py runserver 8888 ``` fenice@fenice:~/WorkSpace/django/mysite$ ./manage.py startapp blog Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/core/management/__init__.py", line 331, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/core/management/__init__.py", line 305, in execute django.setup() File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/apps/registry.py", line 115, in populate app_config.ready() File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/admin/apps.py", line 22, in ready self.module.autodiscover() File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/admin/__init__.py", line 26, in autodiscover autodiscover_modules('admin', register_to=site) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/utils/module_loading.py", line 50, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/admin.py", line 7, in <module> from django.contrib.auth.forms import ( File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/forms.py", line 259, in <module> class SetPasswordForm(forms.Form): File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/forms.py", line 269, in SetPasswordForm help_text=password_validation.password_validators_help_text_html()) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/password_validation.py", line 85, in password_validators_help_text_html help_texts = password_validators_help_texts(password_validators) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/password_validation.py", line 74, in password_validators_help_texts password_validators = get_default_password_validators() File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/utils/lru_cache.py", line 101, in wrapper result = user_function(*args, **kwds) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/password_validation.py", line 21, in get_default_password_validators return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/password_validation.py", line 32, in get_password_validators validators.append(klass(**validator.get('OPTIONS', {}))) File "/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/password_validation.py", line 164, in __init__ with open(password_list_path) as f: IOError: [Errno 2] No such file or directory: u'/usr/local/lib/python2.7/dist-packages/Django-1.9.dev20150709131027-py2.7.egg/django/contrib/auth/common-passwords.txt.gz' ```
django执行python manage.py runserverbao'cuo
最近准备学习django,按照网上的教程装好了大概,然后创建第一个项目, ``` django-admin startproject mytest ``` 创建没毛病,目录中生成了一个文件夹和manage.py,但是再执行 ``` python manage.py runserver ``` 就报错了说:'python' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 找了很多地方都没说原因,环境变量肯定设置了应该,要不然也不会创建成功ba
Django中ajax访问view.py中自定义函数
在template文件夹下的eva.html里使用ajax,和eva文件夹下的view.py进行交互。 view.py中定义函数getvalue,通过该函数可以接收ajax传输值并return回到前端。 但是会报错“not found: /getvalue/” 求助:是不是前端ajax中url的访问地址写错了?如何修改?谢谢大佬们! (view.py, urls.py, settings.py均在eva文件夹下![图片说明](https://img-ask.csdn.net/upload/201909/06/1567755598_180442.png)![图片说明](https://img-ask.csdn.net/upload/201909/06/1567755611_744757.png)![图片说明](https://img-ask.csdn.net/upload/201909/06/1567755621_656129.png)![图片说明](https://img-ask.csdn.net/upload/201909/06/1567755629_63668.png)![图片说明](https://img-ask.csdn.net/upload/201909/06/1567755637_118577.png) )
<python从入门到实践>18章Django联系创建模型Pizzas和Topping时运行migrate时出现错误django.db.utils.OperationalError: no such table: pizzas_pizza
models.py ``` from django.db import models class Pizza(models.Model): name = models.CharField(max_length=5) date_added = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Topping(models.Model): pizza = models.ForeignKey(Pizza,on_delete=models.CASCADE) name = models.TextField date_added = models.DateTimeField(auto_now_add=True) class Meta: verbose_name_plural = 'toppings' def __str__(self): return self.name[:20]+'...' ```
django创建项目时,urls.py报错:No module named 'index.urls'
django创建音乐网站项目时,urls.py写入代码后,pycharm一直报错: No module named 'index.urls' 用idle运行时候就报错: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 创建过程中只修改了urls.py 和setting.py 文件 代码如下: [b]urls.py[/b] from django.contrib import admin from django.urls import path, include from django.conf.urls import url from django.views import static from django.conf import settings urlpatterns = [ path('admin/', admin.site.urls), path('', include('index.urls')), path('ranking.html', include('ranking.urls')), path('play/', include('play.urls')), path('comment/', include('comment.urls')), path('search/', include('search.urls')), path('user/', include('user.urls')), ] [b]settings.py[/b] (部分代码) INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'index', 'ranking', 'user', 'play', 'search', 'comment', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', # 使用中文 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'music.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'index/templates'), os.path.join(BASE_DIR, 'ranking/templates'), os.path.join(BASE_DIR, 'user/templates'), os.path.join(BASE_DIR, 'play/templates'), os.path.join(BASE_DIR, 'comment/templates'), ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'music.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'music_db', 'USER': 'root', 'PASSWORD': '1234', 'HOST': '127.0.0.1', 'POST': '3306', } } 请问这种情况该如何处理呢?求指点
django的model不能创建对应表
我的python的版本是3.4 django的版本是1.7.2 这个是我的models.py文件 from django.db import models class Test(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name 但是python manage.py syncdb同步数据库之后 没有出现blog_test表 只有这些 ![](http://img.bbs.csdn.net/upload/201501/13/1421154027_527365.png) 这是怎么回事啊?
python django models 中的返回值问题
首先是python3,django2.1.4, from django.db import models class Event(models.Model): name = models.CharField(max_length=100) def _str_(self): return self.name 但是显示的结果却是 EventObject, 而不是输入的name的内容。求解!
关于{Django}外链与表关系的一个小问题
## 以下关于article.tag_set.add(tag)这一条代码有点似懂非懂口否为我解惑 ##能不能详细介绍一下它的添加方式怎么怎么运行的 ``` #models.py class Article(models.Model): title = models.CharField(max_length=100) content = models.TextField() class Meta: db_table = 'article' class Tag(models.Model): name = models.CharField(max_length=50) tags = models.ManyToManyField("Article") class Meta: db_table = 'tag' ``` ``` #views.py def index(request): article = Article.objects.first() tag = Tag(name='热门标签') tag.save() article.tag_set.add(tag) return HttpResponse("asdfghjk") ```
求解!!!!!请问怎样调用在django自带的数据库中新建立的数据表?
下面是view.py 的一部分代码,我想把用户输入的数据存到“书籍信息表”,但是 不知道哪里出问题了,django自带了sqlite3数据库,要使用在sqlite3里新建立的表要不要先连接,求解!!! 数据表分别有:用户信息表、书籍信息表、管理员信息表 from django.shortcuts import render, redirect from .models import 用户信息表, 书籍信息表, 管理员信息表 from django.contrib.auth import authenticate, login, logout from django.contrib.auth.models import User from django.contrib import auth def sell(request): if request.method == ‘GET’: return render(request, ‘我要卖.html’) elif request.method == ‘POST’: 书名 = request.POST【‘书名’】 作者 = request.POST【‘作者’】 try: ISDN码 = request.POST【‘ISDN’】 出版社 = request.POST【‘出版社’】 卖家联系方式 = request.POST【‘电话’】 product = 书籍信息表() product.book_name = 书名 product.author = 作者 product.isdn码 = ISDN码 product.publisher = 出版社 product.Tel = 卖家联系方式 product.save() return redirect(‘主页’) except Exception as err: return render(redirect, ‘我要卖.html’, {‘错误’: ‘请填写完整信息!’})
执行python manage.py migrate命令有问题
我在windows系统搭建了开发环境,使用的是pytohn2.7版本,在本地开发环境验证测试,执行python manage.py migrate命令有问题: 我在这个位置执行的命令: ![图片说明](https://img-ask.csdn.net/upload/201912/16/1576467780_425609.png) 报错如下: ![图片说明](https://img-ask.csdn.net/upload/201912/16/1576467889_633346.png) D:\python2.7\python2.7\Lib\site-packages\django\conf\project_template>python manage.py migrate Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "D:\python2.7\python2.7\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line utility.execute() File "D:\python2.7\python2.7\lib\site-packages\django\core\management\__init__.py", line 303, in execute settings.INSTALLED_APPS File "D:\python2.7\python2.7\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__ self._setup(name) File "D:\python2.7\python2.7\lib\site-packages\django\conf\__init__.py", line 44, in _setup self._wrapped = Settings(settings_module) File "D:\python2.7\python2.7\lib\site-packages\django\conf\__init__.py", line 92, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "D:\python2.7\python2.7\lib\importlib\__init__.py", line 37, in import_module __import__(name) ImportError: No module named {{ project_name }}.settings 求大神指教,是我执行的目录位置有问题吗?
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时想着能进去就不错了,管他哪个岗呢,就同意了面试...
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体...
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
Spring Boot2 系列教程(十七)SpringBoot 整合 Swagger2
前后端分离后,维护接口文档基本上是必不可少的工作。 一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了。当然这是一种非常理想的状态,实际开发中却很少遇到这样的情况,接口总是在不断的变化之中,有变化就要去维护,做过的小伙伴都知道这件事有多么头大!还好,有一些工具可以减轻我们的工作量,Swagger2 就是其中之一,至于其他类似功能但是却收费的软...
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
天天学JAVA-JAVA基础(6)
如果觉得我写的还行,请关注我的博客并且点个赞哟。本文主要介绍JAVA 中最常使用字符串常量String相关知识。 1.String简介 2.创建字符串对象两种方式的区别 3.String常用的方法 4.String的不可变性 5.一道阿里面试题,你会做吗? 1.String简介 1.1String源码 首先看一段String源码,String主要实现了Serializable、Compar...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
2020 网络课 智慧树自动刷课代码,自动跳转,自动答题并关闭弹窗,自动1.5倍速静音
刷课一时爽,一直刷课一直爽! 终于让我找到了这个黑客代码了,教程开始: 只限谷歌浏览器和火狐浏览器使用,如果第一次失败,请重新试一下次 将下面代码复制后,进入浏览器按F12键,先点击console 然后Ctrl+v复制代码 最后按回车键即可 var ti = $("body"); var video = $(".catalogue_ul1 li[id*=video-]"); var i = 1;...
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
致 Python 初学者
文章目录1. 前言2. 明确学习目标,不急于求成,不好高骛远3. 在开始学习 Python 之前,你需要做一些准备2.1 Python 的各种发行版2.2 安装 Python2.3 选择一款趁手的开发工具3. 习惯使用IDLE,这是学习python最好的方式4. 严格遵从编码规范5. 代码的运行、调试5. 模块管理5.1 同时安装了py2/py35.2 使用Anaconda,或者通过IDE来安装模
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
羞,Java 字符串拼接竟然有这么多姿势
二哥,我今年大二,看你分享的《阿里巴巴 Java 开发手册》上有一段内容说:“循环体内,拼接字符串最好使用 StringBuilder 的 append 方法,而不是 + 号操作符。”到底为什么啊,我平常一直就用的‘+’号操作符啊!二哥有空的时候能否写一篇文章分析一下呢? 就在昨天,一位叫小菜的读者微信我说了上面这段话。 我当时看到这条微信的第一感觉是:小菜你也太菜了吧,这都不知道为啥啊!我估...
写1行代码影响1000000000人,这是个什么项目?
不带钱不带卡,只带手机出门就能畅行无阻,这已是生活的常态。益普索发布的《2019第一季度第三方移动支付用户研究》报告显示,移动支付在手机网民中的渗透率高达95.1%,截至今年1月,支付宝全球用户数已经突破10亿。你或许每天都会打开支付宝,付款购物、领取权益、享受服务……但你或许不知道的是,在这个方便、快捷、智能化的APP背后,有一群年轻的技术人,用智慧和创新让它每天都变得更“聪明”一点。 ...
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
一点一滴记录 Java 8 stream 的使用
日常用到,一点一滴记录,不断丰富,知识积累,塑造自身价值。欢迎收藏 String 转 List String str = 1,2,3,4; List&lt;Long&gt; lists = Arrays.stream(str.split(",")).map(s -&gt; Long.parseLong(s.trim())).collect(Collectors.toList()); Lis...
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
相关热词 如何提升c#开发能力 矩阵乘法c# c#调用谷歌浏览器 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天
立即提问