我对 django 框架很陌生。
# Create your views here.
import urllib2
import json
import urllib
from .models import Apiclass
from django.shortcuts import render_to_response
from django.conf import settings as config
def home(request):
obj = Apiclass()
def postme(request):
url = config.API_PROTOCOL+config.API_DOMAIN+config.API_SECURE_USER_URL
# user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = {'username' : 'waheeda@auction.com',
'password' : '12345678'
}
# headers = { 'Content-Type' : "application/json" }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = json.loads(response.read())
return render_to_response("home.html",{'postme':the_page})
而 ApiClass 在 models/Apiclass.py 下
我尝试了很多方法来导入模型 ApiClass,例如 - from app1.models import Apiclass - from .models import Apiclass
但它仍然不起作用它给了我这样的错误
TypeError at /api
'module' object is not callable
Apiclass.py
当我可以创建一切都应该好的对象时,我只是评论所有的实现。这是 Apiclass 代码
import urllib2
import urllib
import json
from django.conf import settings as config
# Create your models here.
class Apiclass:
api_domain = config.API_DOMAIN