我创建了一个简单的Django Rest Framework API,以尝试将数据从Postgresql中提取到我正在构建的Django网站中。我进入Django的可浏览API,并以正确的json格式查看前几行,但随后浏览器(Firefox)抱怨该网站正在减慢我的浏览器的速度,并且只是循环-从未完成。当我不使用浏览器GET请求API数据时,也会发生同样的情况。
我有很多数据:15k行x 14列= 210k数据点-这可能是问题吗?
版本:
Django = 2.1.1
DjangoRestFramework = 3.8.2
代码: models.py
from django.db import models
# Create your models here.
class dbrealestate(models.Model):
hash_id = models.BigIntegerField(primary_key=True, blank=True)
latitude = models.FloatField(blank=True, null=True)
longitude = models.FloatField(blank=True, null=True)
yields = models.FloatField(blank=True, null=True)
price = models.BigIntegerField(blank=True, null=True)
garden_area = models.FloatField(blank=True, null=True)
parking = models.TextField(blank=True, null=True)
terass = models.TextField(blank=True, null=True)
loggia = models.TextField(blank=True, null=True)
cellar = models.TextField(blank=True, null=True)
elevator = models.NullBooleanField()
garage = models.TextField(blank=True, null=True)
balcony_size = models.TextField(blank=True, null=True)
num_floor = models.BigIntegerField(blank=True, null=True)
num_rooms = models.BigIntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'realestate'
serializer.py
from .models import dbrealestate
from rest_framework import serializers
class realestate_serializer(serializers.ModelSerializer):
class Meta:
model = dbrealestate
fields = ('hash_id', 'latitude', 'longitude', 'price', 'yields',
'num_floor', 'num_rooms', 'elevator', 'garage',
'balcony_size', 'garden_area', 'parking', 'terass',
'loggia', 'cellar')
views.py
from django.shortcuts import render
from rest_framework import viewsets
from .serializers import realestate_serializer
from .models import dbrealestate
class realestate_viewset(viewsets.ModelViewSet):
queryset = dbrealestate_full.objects.all()
serializer_class = realestate_serializer
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from rest_framework import routers
from listings_api import views
router = routers.DefaultRouter()
router.register(r'listings_api', views.realestate_viewset)
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
我遇到了很多错误,其中很多似乎与我遇到的错误无关:
Firefox控制台:
GET
http://127.0.0.1:8000/listings_api/
[HTTP/1.1 200 OK 5680ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/jquery-3.3.1.min.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/ajax-form.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/csrf.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/bootstrap.min.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/prettify-min.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/css/bootstrap.min.css
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/css/bootstrap-tweaks.css
Error in parsing value for ‘-webkit-text-size-adjust’. Declaration dropped. bootstrap.min.css:5:133
Unknown pseudo-class or pseudo-element ‘-webkit-inner-spin-button’. Ruleset ignored due to bad selector. bootstrap.min.css:5:1544
Unknown pseudo-class or pseudo-element ‘-webkit-search-cancel-button’. Ruleset ignored due to bad selector. bootstrap.min.css:5:1778
Unknown property ‘orphans’. Declaration dropped. bootstrap.min.css:5:2693
Unknown property ‘widows’. Declaration dropped. bootstrap.min.css:5:2702
Unknown property ‘-moz-osx-font-smoothing’. Declaration dropped. bootstrap.min.css:5:3678
Error in parsing value for ‘outline’. Declaration dropped. bootstrap.min.css:5:15694
Error in parsing value for ‘margin-top’. Declaration dropped. bootstrap.min.css:5:35721
Error in parsing value for ‘outline’. Declaration dropped. bootstrap.min.css:5:35952
Unknown pseudo-class or pseudo-element ‘-ms-input-placeholder’. Ruleset ignored due to bad selector. bootstrap.min.css:5:36879
Unknown pseudo-class or pseudo-element ‘-webkit-input-placeholder’. Ruleset ignored due to bad selector. bootstrap.min.css:5:36926
Unknown pseudo-class or pseudo-element ‘-ms-expand’. Ruleset ignored due to bad selector. bootstrap.min.css:5:36978
Expected media feature name but found ‘-webkit-min-device-pixel-ratio’. bootstrap.min.css:5:37313
Error in parsing value for ‘margin-top’. Declaration dropped. bootstrap.min.css:5:38426
Unknown property ‘user-select’. Declaration dropped. bootstrap.min.css:5:45473
Error in parsing value for ‘outline’. Declaration dropped. bootstrap.min.css:5:45657
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:45999
Error in parsing value for ‘border-top’. Declaration dropped. bootstrap.min.css:5:54924
Expected ‘none’, URL, or filter function but found ‘progid’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:56292
Error in parsing value for ‘border-bottom’. Declaration dropped. bootstrap.min.css:5:56836
Unrecognized at-rule or error parsing at-rule ‘@-o-keyframes’. bootstrap.min.css:5:84279
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:85214
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:86119
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:86745
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:87377
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:88007
Unknown property ‘zoom’. Declaration dropped. bootstrap.min.css:5:88444
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:105686
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:105795
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:107004
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:107057
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:108207
Unknown property ‘line-break’. Declaration dropped. bootstrap.min.css:5:108245
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:108269
Unknown property ‘line-break’. Declaration dropped. bootstrap.min.css:5:110252
Expected media feature name but found ‘transform-3d’. bootstrap.min.css:5:112089
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:113426
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:113582
Expected ‘none’, URL, or filter function but found ‘progid’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:113841
Error in parsing value for ‘background-image’. Declaration dropped. bootstrap.min.css:5:114125
Expected ‘none’, URL, or filter function but found ‘progid’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:114384
Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped. bootstrap.min.css:5:114609
Expected color but found ‘#000\9 ’. Error in parsing value for ‘background-color’. Declaration dropped. bootstrap.min.css:5:115558
Unrecognized at-rule or error parsing at-rule ‘@-ms-viewport’. bootstrap.min.css:5:117843
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/css/prettify.css
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/js/default.js
[HTTP/1.1 200 OK 0ms]
[Show/hide message details.] GET
http://127.0.0.1:8000/static/rest_framework/css/default.css
[HTTP/1.1 200 OK 0ms]
Unknown property ‘-moz-box-shadow’. Declaration dropped. bootstrap-tweaks.css:129:22
Unknown property ‘-moz-box-shadow’. Declaration dropped. prettify.css:17:22
Source map error: request failed with status 404
Resource URL: http://127.0.0.1:8000/static/rest_framework/css/bootstrap.min.css
Source Map URL: bootstrap.min.css.map[Learn More]
Error: Script terminated by timeout at:
E@http://127.0.0.1:8000/static/rest_framework/js/prettify-min.js:16:363
m@http://127.0.0.1:8000/static/rest_framework/js/prettify-min.js:26:481
window.prettyPrint@http://127.0.0.1:8000/static/rest_framework/js/prettify-min.js:27:316
@http://127.0.0.1:8000/static/rest_framework/js/default.js:3:3
l@http://127.0.0.1:8000/static/rest_framework/js/jquery-3.3.1.min.js:2:29373
a/</c<@http://127.0.0.1:8000/static/rest_framework/js/jquery-3.3.1.min.js:2:29677
Django Bash日志(已缩短):
Traceback (most recent call last):
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
Traceback (most recent call last):
Traceback (most recent call last):
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
Traceback (most recent call last):
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\phili\Miniconda3\envs\django\lib\socket.py", line 594, in write
return self._sock.send(b)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
AND
Traceback (most recent call last):
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 625, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 625, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 625, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 681, in __init__
self.handle()
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 681, in __init__
self.handle()
File "C:\Users\phili\Miniconda3\envs\django\lib\socketserver.py", line 681, in __init__
self.handle()
File "C:\Users\phili\Miniconda3\envs\django\lib\site-packages\django\core\servers\basehttp.py", line 154, in handle
handler.run(self.server.get_app())
File "C:\Users\phili\Miniconda3\envs\django\lib\site-packages\django\core\servers\basehttp.py", line 154, in handle
handler.run(self.server.get_app())
File "C:\Users\phili\Miniconda3\envs\django\lib\site-packages\django\core\servers\basehttp.py", line 154, in handle
handler.run(self.server.get_app())
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\simple_server.py", line 36, in close
self.status.split(' ',1)[0], self.bytes_sent
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\simple_server.py", line 36, in close
self.status.split(' ',1)[0], self.bytes_sent
File "C:\Users\phili\Miniconda3\envs\django\lib\wsgiref\simple_server.py", line 36, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
TypeError: 'NoneType' object is not subscriptable