【问题标题】:What's wrong with that django app?那个 django 应用程序有什么问题?
【发布时间】:2012-08-02 20:39:55
【问题描述】:

我正在关注该教程 http://thecodachi.blogspot.com/2012/03/django-tastypie-with-android-client.htmlhttps://github.com/Mbosco/tastypie-api-example
我在教程中做了所有事情,但是当我运行“localhost:8000/api/recipes/?format=json”时出现错误“没有名为 recipe_resource.urls 的模块” 你能帮我解决一下吗?

【问题讨论】:

  • 你没有名为recipe_resource.py的文件,是吗?
  • 不,它被称为 queryset = Recipe.objects.all() 并且指的是Recipe
  • 这不是他要问的。你真的有一个名为“recipe_resource.py”的文件吗?
  • 尝试将url(r'^api/', include('recipe_resource.urls')), 更改为:url(r'^api/', include(recipe_resource.urls)),(不带简单引号)
  • 谢谢,它有效。还有一个问题,如果我使用http post从android发布食谱(名称和内容),我应该使用什么方法来记录从android发送的数据到django数据库?

标签: django tastypie


【解决方案1】:

尝试改变这一点

url(r'^api/', include('recipe_resource.urls')), 

用这个:

url(r'^api/', include(recipe_resource.urls)), #without the simple quotes in the "include" parameter

【讨论】:

    【解决方案2】:

    在我的美味派实现中,我有类似以下内容:

    from tastypie.api import Api
    from recipes.api import RecipeResource
    
    v1_api = Api(api_name='v1')
    v1_api.register(RecipeResource())
    
    urlpatterns += patterns('',
        (r'^api/', include(v1_api.urls)),
    )
    

    也许,试试吧。即使它不能改善这种情况,无论如何,您还是希望这样做,因为否则您无法添加多个资源。

    【讨论】:

    • 我试过了,我得到了那个错误“name 'urlpatterns' is not defined”
    • 好的。首先,它需要进入你的主 urls.py 文件,而不是你的应用程序,其次,它需要在你第一次定义 urlpatterns 之后出现。如果是第一次,那么只需删除+
    • 我想它可以工作,即使我这次遇到“找不到页面(404)”错误,对吧?
    • 在这种情况下,我如何访问管理页面?
    • 嗯?第一次使用urlpatterns 使用=,每隔一段时间使用+=
    猜你喜欢
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多