问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

如何用django.db(如何用django发送post请求)

发布网友 发布时间:2024-10-02 13:31

我来回答

1个回答

热心网友 时间:2024-10-03 11:48

本篇文章给大家谈谈如何用django.db,以及如何用django发送post请求对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

1、如何在Django中使用第三方库2、django使用已有的数据库表怎么建立model3、python3.6下如何用Django1.9创建数据库报错4、如何独立使用django的数据库访问功能5、如何使用django和mysqlconnector6、如何在DJANGO里,向有外键的DB里插入数据如何在Django中使用第三方库

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.

'NAME': 'demo.db',# Or path to database file if using sqlite3.

# The following settings are not used with sqlite3:

'USER': '',

'PASSWORD': '',

'HOST': '',# Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.

'PORT': '',# Set to empty string for default.

}

}

INSTALLED_APPS = (

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.messages',

'django.contrib.staticfiles',

# Uncomment the next line to enable the admin:

# 'django.contrib.admin',

# Uncomment the next line to enable admin documentation:

# 'django.contrib.admindocs',

'south',

'LearnSouth',

'books',

)

django使用已有的数据库表怎么建立model

在网上看到都是使用Django的models和makemigration,migrate命令来创建新表,并使用。可是我的数据已经存在了已经创建好,并且已经存储有数据了,不能再重新创建新表了。了解Django的表明和models名称的映射关系就可以让Django使用已经存在的表。

假如在Django存在models如下:

[python]?view plain?copy

from?django.db?import?models

#?Create?your?models?here.

class?Sciencenews(models.Model):

id?=?models.CharField(max_length=36,primary_key=True)

first_module?=?models.CharField(max_length=30,default="News")

second_module?=?models.CharField(max_length=30,default="Latest?News")

title?=?models.CharField(max_length=300)

author?=?models.CharField(max_length=60,null=True)

publish_date?=?models.CharField(max_length=35,null=True)

content?=?models.TextField(null=True)

crawl_date?=?models.CharField(max_length=35,null=True)

from_url?=?models.CharField(max_length=350,null=True)

执行数据迁移命令:

[python]?view plain?copy

python?manage.py?makemigration

python?manage.py?migrate

会在数据库中生成名称为show_sciencenews的数据表。show为应用名称,此处我的应用名称为show。可以看到Django创建表的命名规则:应用名_模型名。

我的存储爬取到的数据的表格名称原来为science_news,想要Django使用它,而不是创建新的表,只需要把的它的名称改为:应用名_要与该表映射的models名称,在此处我改为show_sciencenews。然后使用如上的数据迁移命令,这时可能会提示数据表已经存在的错误,不用理会,models已经和数据表映射上了。接下来只需要正常使用models和数据表就可以了。

python3.6下如何用Django1.9创建数据库报错

错误描述

python==3.5

django==1.7

django创建项目时报错如下:

Traceback (most recent call last):

File "/root/envs/django-test/bin/django-admin", line 11, in module

sys.exit(execute_from_command_line())

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line

utility.execute()

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/management/__init__.py", line 354, in execute

django.setup()

File "/root/envs/django-test/lib/python3.5/site-packages/django/__init__.py", line 18, in setup

from django.utils.log import configure_logging

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/log.py", line 10, in module

from django.views.debug import ExceptionReporter, get_exception_reporter_filter

File "/root/envs/django-test/lib/python3.5/site-packages/django/views/debug.py", line 10, in module

from django.http import (HttpResponse, HttpResponseServerError,

File "/root/envs/django-test/lib/python3.5/site-packages/django/http/__init__.py", line 4, in module

from django.http.response import (HttpResponse, StreamingHttpResponse,

File "/root/envs/django-test/lib/python3.5/site-packages/django/http/response.py", line 13, in module

from django.core.serializers.json import DjangoJSONEncoder

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/serializers/__init__.py", line 23, in module

from django.core.serializers.base import SerializerDoesNotExist

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/serializers/base.py", line 6, in module

from django.db import models

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/__init__.py", line 6, in module

from django.db.models.query import Q, QuerySet, Prefetch# NOQA

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/query.py", line 13, in module

from django.db.models.fields import AutoField, Empty

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 18, in module

from django import forms

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/__init__.py", line 6, in module

from django.forms.fields import *# NOQA

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/fields.py", line 18, in module

from django.forms.utils import from_current_timezone, to_current_timezone

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/utils.py", line 15, in module

from django.utils.html import format_html, format_html_join, escape

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/html.py", line 16, in module

from .html_parser import HTMLParser, HTMLParseError

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/html_parser.py", line 12, in module

HTMLParseError = _html_parser.HTMLParseError

AttributeError: module 'html.parser' has no attribute 'HTMLParseError'

(django-test) root@localhost:~/source/djangotest# django-admin startproject superlists

Traceback (most recent call last):

File "/root/envs/django-test/bin/django-admin", line 11, in module

sys.exit(execute_from_command_line())

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line

utility.execute()

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/management/__init__.py", line 354, in execute

django.setup()

File "/root/envs/django-test/lib/python3.5/site-packages/django/__init__.py", line 18, in setup

from django.utils.log import configure_logging

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/log.py", line 10, in module

from django.views.debug import ExceptionReporter, get_exception_reporter_filter

File "/root/envs/django-test/lib/python3.5/site-packages/django/views/debug.py", line 10, in module

from django.http import (HttpResponse, HttpResponseServerError,

File "/root/envs/django-test/lib/python3.5/site-packages/django/http/__init__.py", line 4, in module

from django.http.response import (HttpResponse, StreamingHttpResponse,

File "/root/envs/django-test/lib/python3.5/site-packages/django/http/response.py", line 13, in module

from django.core.serializers.json import DjangoJSONEncoder

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/serializers/__init__.py", line 23, in module

from django.core.serializers.base import SerializerDoesNotExist

File "/root/envs/django-test/lib/python3.5/site-packages/django/core/serializers/base.py", line 6, in module

from django.db import models

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/__init__.py", line 6, in module

from django.db.models.query import Q, QuerySet, Prefetch# NOQA

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/query.py", line 13, in module

from django.db.models.fields import AutoField, Empty

File "/root/envs/django-test/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 18, in module

from django import forms

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/__init__.py", line 6, in module

from django.forms.fields import *# NOQA

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/fields.py", line 18, in module

from django.forms.utils import from_current_timezone, to_current_timezone

File "/root/envs/django-test/lib/python3.5/site-packages/django/forms/utils.py", line 15, in module

from django.utils.html import format_html, format_html_join, escape

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/html.py", line 16, in module

from .html_parser import HTMLParser, HTMLParseError

File "/root/envs/django-test/lib/python3.5/site-packages/django/utils/html_parser.py", line 12, in module

HTMLParseError = _html_parser.HTMLParseError

AttributeError: module 'html.parser' has no attribute 'HTMLParseError'12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576771234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677

原因

HTMLParseError在pythons3.5已经没有了

解决方法

将python版本回退到3.3或3.4

升级django版本

如何独立使用django的数据库访问功能

1. 安装Django

[plain] view plain copy

cd Django-1.4

python setup.py install

2. 安装postgresql的客户端:

[plain] view plain copy

sudo apt-get install -y postgresql-client-9.1 python-psycopg2

3. 新建project:

[plain] view plain copy

django-admin.py startproject myproject

4. 在myproject下新建app:

[plain] view plain copy

python manage.py startapp myapp

4. 新增环境变量:

编辑/etc/profile文件,在末尾加入以下语句:

[plain] view plain copy

span style="color:#FF0000;"export PYTHONPATH=$PYTHONPATH:/home/yc/src/myproject

export DJANGO_SETTINGS_MODULE=mypro

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
喉咙痒咳嗽没有痰吃什么药 喉咙痒咳嗽有异物感吃什么药 为什么我会对男友更敏感? 自考学位证申请需要什么条件 自学考试怎么申请学士学位? 北京哪里花卉市场最大?有地址吗? 鸡狗49 ,100条腿向前走,几只鸡?几只狗?(不用两元一次方程解题) 鸡狗四十九,100条腿地上走.问:多少只鸡,多少条狗? 鸡和狗49只一百条腿地上走问有多少只鸡和多少只狗 狗鸡四十九,一百条腿地上走,问:多少只鸡,多少只狗? 手机端如何访问django? 手机怎么访问django(手机怎么访问路由器管理页面) django怎么使用数据库(django的数据库) python多久可以工作 手机端淘宝宝贝详情的尺寸要求是多大? 香蕉搭配什么吃好 电气控制设计软件软件信息 拓扑图制作软件有哪些 强电布线软件有哪些 IBM MQ是什 新概念英语随课练1目录 我的控制面板里只有一个本地连接,没有看到无线网络连接,是不是说明我... 电脑只有本地连接,台式电脑怎么连无线? 如何在WPS表格中使用阶梯计算公式?业绩10单以下0元,10-20单20元/... 肺部磨玻璃样病变GGO发现后怎么办 肺上磨玻璃结节是什么 怎么使用罗技RGB键盘? “经纬得无妄”的出处是哪里 “奕世希末光”的出处是哪里 “诸巂出相望”的出处是哪里 路上读书APP跟路上读书FM是同一个听书软件吗? ...FM,还有哪些值得推荐的听书软件,或者像路上读书这样的移动音频... 怎么看待路上读书音频图书馆、喜马拉雅和荔枝FM三者间的区别? “每逢佳节倍思亲”的出处是哪里 升级贷额度有有效期吗? 批了三万的升级贷额度,这钱必须一次性借完吗? 跟新网银行好人贷一样的平台有哪些 建设银行卡可以异地开通网银吗? 喝凉开水也拉肚孑,吃凉菜也拉肚子,今常拉血是什么原因 光遇狮子头是哪个先祖 狮子头先祖位置 光遇狮子头面具先祖在哪_狮子头面具先祖位置分享 光遇狮子头是哪个先祖-狮子头先祖位置介绍 38.五粮草箱冠群芳 离高考只有7天了(可能还不到),英语只有40分左右怎么办? 麦格米特触摸屏软件哪里能下载? 阴阳师相伴相随服各种ssr碎片价位 阴阳师妖刀姬怎么获得-妖刀姬获得方法 《阴阳师》刷ssr碎片攻略介绍_《阴阳师》刷ssr碎片攻略是什么_百度知 ... 铜仁夜宵好吃推荐? 滁州美食推荐攻略? ...我太天真了,告诉了他微信号和密码,现在登不上去了。