在django-tastypie中没有名为urls的模块 [英] No module named urls in django-tastypie
本文介绍了在django-tastypie中没有名为urls的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我也做了modelclass Entry。当我在url上运行 http:// localhost:8000 / api / v1 / 时,会抛出错误
#myapp / api / resources.py
from django.contrib.auth.models import来自tastypie的用户
.authorization import Authorization
from tastypie import fields
from tastypie.resources import ModelResource,ALL,ALL_WITH_RELATIONS
from myapp.models import Entry
class UserResource (ModelResource):
class Meta:
queryset = User.objects.all()
resource_name ='user'
excludes = ['email','password','is_active ','is_staff','is_superuser']
filtering = {
'username':ALL,
}
class EntryResource(ModelResource)
user = fields.ForeignKey(UserResource,'user')
class Meta:
queryset = Entry.objects.all()
resource_name ='entry'
authorization = Autho rization()
filtering = {
'user':ALL_WITH_RELATIONS,
'pub_date':['exact','lt','lte','gte','gt'],
}
urls.py
from django.conf.urls.defaults import *
from tastypie.api import Api
from myapp.api.resources import EntryResource,UserResource
v1_api = Api(api_name ='v1')
v1_api.register(UserResource())
v1_api.register(EntryResource())
urlpatterns = patterns(' ',
#这里的普通爵士乐
(r'^ blog /',include('myapp.urls')),
(r'^ api /',include v1
它是抛出消息没有模块命名urls 。任何想法?
解决方案
而不是从django.conf
.urls.defaults import *
您可以尝试导入,如下所示,它可以从django工作,
。 conf.urls import *
I just copy paste tastypie sample code to get know how it works. The code is as follows. I have made modelclass Entry also. When i run http://localhost:8000/api/v1/ on url it throws error
# myapp/api/resources.py
from django.contrib.auth.models import User
from tastypie.authorization import Authorization
from tastypie import fields
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from myapp.models import Entry
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
filtering = {
'username': ALL,
}
class EntryResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Entry.objects.all()
resource_name = 'entry'
authorization = Authorization()
filtering = {
'user': ALL_WITH_RELATIONS,
'pub_date': ['exact', 'lt', 'lte', 'gte', 'gt'],
}
urls.py
from django.conf.urls.defaults import *
from tastypie.api import Api
from myapp.api.resources import EntryResource, UserResource
v1_api = Api(api_name='v1')
v1_api.register(UserResource())
v1_api.register(EntryResource())
urlpatterns = patterns('',
# The normal jazz here...
(r'^blog/', include('myapp.urls')),
(r'^api/', include(v1_api.urls)),
)
It is throwing message "No module named urls" . Any ideas?
解决方案
Instead of ,
from django.conf.urls.defaults import *
You can try import like below and it will works,
from django.conf.urls import *
这篇关于在django-tastypie中没有名为urls的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文