所以我試圖打開在我看來,使用此代碼從這個JSON文件打印數據:AttributeError的類型的對象有沒有屬性
from django.shortcuts import render
import json
class OnlicarView():
import json
from pprint import pprint
with open('C:/Python34/Scripts/onlicar/mytest/onlicar/static/json/vehicles.json') as data_file:
data = json.load(data_file)
pprint(data)
這裏是我的應用程序網址:
from django.conf.urls import url
from onlicar import views
urlpatterns = [
url(r'^onlicar/$', views.OnlicarView.as_view(), name='onlicar_signup'
)
]
這是我的根地址:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^onlicar/', include('onlicar.urls'))
我遇到了應用程序url的問題。我收到一個錯誤,說有一個屬性錯誤,我不知道如何解決它。
因爲我從JSON文件中獲取數據,所以目前我的模型中沒有任何內容。我的意思是在模特中有什麼?
我的JSON文件現在正在打印,但我如何將它呈現爲HTML?
以下是錯誤:
Unhandled exception in thread started by <function check_errors.<locals>.
at 0x03F9C4B0>
Traceback (most recent call last):
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\utils\autore
", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\managem
mands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\managem
e.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\managem
e.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\checks\
y.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\checks\
", line 14, in check_url_config
return check_resolver(resolver)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\core\checks\
", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\utils\functi
", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\urls\resolve
line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_m
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\utils\functi
", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\urls\resolve
line 306, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python34\Scripts\onlicar\lib\importlib\__init__.py", line 109,
ort_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlo
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_re
File "C:\Python34\Scripts\onlicar\mytest\mytest\urls.py", line 21, in <
url(r'^onlicar/', include('onlicar.urls'))
File "C:\Python34\Scripts\onlicar\lib\site-packages\django\conf\urls\__
py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "C:\Python34\Scripts\onlicar\lib\importlib\__init__.py", line 109,
ort_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlo
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_re
File "C:\Python34\Scripts\onlicar\mytest\onlicar\urls.py", line 5, in <
url(r'^onlicar/$', views.OnlicarView.as_view(), name='onlicar_signup'
AttributeError: type object 'OnlicarView' has no attribute 'as_view'
可以顯示完整的錯誤.. ?? – shiva