有没有人遇到过这样的错误?当我尝试使用表单登录,并检查来自mysql的数据时,我收到错误:
Request Method: POST
Request URL: http://tesmyapp.loc/post/login/
Django Version: 1.9.7
Exception Type: OperationalError
Exception Value:
near "����������": **syntax error**
Exception Location: /myapp/env/lib/python2.7/site-packages/django/db/backends/sqlite3/operations.py in _quote_params_for_last_executed_query, line 129
Python Executable: /myapp/env/bin/uwsgi
我不确定这是mysql的错误,因为当我尝试发布时没有检查数据库,错误仍然出现
在views.py中的功能
@csrf_protect
def post_login(request):
if request.method == 'POST':
username = request.POST.get("username", "")
password = request.POST.get("password", "")
mylogin = check_login(username, password)
if mylogin > 0:
occur = "success"
request.session['member'] = username
return HttpResponseRedirect("/home")
如果有人遇到此错误,请分享解决方案。感谢
回溯:
Environment:
Request Method: POST
Request URL: http://tesmyapp.loc/post/login/
Django Version: 1.9.7
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'login']
Installed 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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/myapp/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
235. response = middleware_method(request, response)
File "/myapp/env/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
50. request.session.save()
File "/myapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
80. return self.create()
File "/myapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in create
49. self._session_key = self._get_new_session_key()
File "/myapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_new_session_key
158. if not self.exists(session_key):
File "/myapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in exists
45. return self.model.objects.filter(session_key=session_key).exists()
File "/myapp/env/lib/python2.7/site-packages/django/db/models/query.py" in exists
651. return self.query.has_results(using=self.db)
File "/myapp/env/lib/python2.7/site-packages/django/db/models/sql/query.py" in has_results
501. return compiler.has_results()
File "/myapp/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in has_results
819. return bool(self.execute_sql(SINGLE))
File "/myapp/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
848. cursor.execute(sql, params)
File "/myapp/env/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
83. sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/myapp/env/lib/python2.7/site-packages/django/db/backends/sqlite3/operations.py" in last_executed_query
140. params = self._quote_params_for_last_executed_query(params)
File "/myapp/env/lib/python2.7/site-packages/django/db/backends/sqlite3/operations.py" in _quote_params_for_last_executed_query
129. return cursor.execute(sql, params).fetchone()
Exception Type: OperationalError at /login
Exception Value: near "����������": syntax error
python manage.py migrate:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/myapp/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/myapp/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/myapp/env/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/myapp/env/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/myapp/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/myapp/env/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/myapp/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/myapp/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/myapp/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/myapp/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 6: ordinal not in range(128)
答案 0 :(得分:0)
我解决了将数据库从sqlite更改为mysql的问题