No module named urls in django-tastypie

被刻印的时光 ゝ 提交于 2019-12-11 19:28:34

问题


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?


回答1:


This error is shwing because there is no module named urls.py in myapp package. create a module urls.py in myapp package




回答2:


You should try:

(r'^api/', include('v1_api.urls')),



回答3:


Instead of

from django.conf.urls.defaults import *

You can try import like this

from django.conf.urls import *


来源:https://stackoverflow.com/questions/10527762/no-module-named-urls-in-django-tastypie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!