小编Vic*_*mer的帖子

为什么 Django 迁移更改字段(AlterField)没有被触及?

当我进行迁移时,python manage.py makemigrations wall 我在控制台中看到 Django (1.8.12) 告诉我一长串涉及的字段:

Migrations for 'wall':
  0079_auto_20170302_0024.py:
    - Add field periodic_task_interval to userproject
    - Alter field bank_problems on bankireference
    - Alter field bank_problems_category on bankireference
    - Alter field bank_products on bankireference
    - Alter field bank_products_category on bankireference
    - Alter field extr_category on bankireference
    - Alter field extr_words on bankireference
    - Alter field neg_features on bankireference
    - Alter field neutral_features on bankireference
    - Alter field pos_features on bankireference
    - Alter field tonality_category on bankireference
    - …
Run Code Online (Sandbox Code Playgroud)

python django django-migrations

6
推荐指数
1
解决办法
2214
查看次数

Django mongonaut:'您无权访问此内容.'

我从这里得到了简单的Django + Mongoengine应用程序示例https://github.com/sneawo/django_mongo_test 这是一个简单的博客应用程序,用于存储Mongodb中的帖子.现在我想要管理界面,为此我找到了django-mongonaut http://django-mongonaut.readthedocs.org/en/latest/installation.html

我通过了所有安装说明,但仍然在尝试访问时localhost:8000/mongonaut/我看到您无权访问此内容.什么是最糟糕的 - 没有任何登录表格.

这是我的mongoadmin.py

# myapp/mongoadmin.py   http://django-mongonaut.readthedocs.org/en/latest/configuration.html

# Import the MongoAdmin base class
from mongonaut.sites import MongoAdmin

# Import your custom models
from blog.models import Post, Tag

# Instantiate the MongoAdmin class
# Then attach the mongoadmin to your model
Post.mongoadmin = MongoAdmin()
Tag.mongoadmin = MongoAdmin()
Run Code Online (Sandbox Code Playgroud)

我是django的新手,这是我与Django + Mongodb合作的最后一次机会,我花了几天时间浏览我在网上找到的多个教程 - 尝试使用mongodb-engine和其他选项的django-nonrel.

我真的很沮丧,因为我找不到完整的工作教程,其中一些有用,但有意外错误.我也尝试过Quokka http://quokkaproject.org/但它是alpha,有些页面也不起作用......

python django mongodb mongoengine

5
推荐指数
1
解决办法
537
查看次数

Python JSON到CSV-编码错误,UnicodeDecodeError:“ charmap”编解码器无法解码字节

我在将嵌套的JSON转换为CSV时遇到问题。为此,我使用https://github.com/vinay20045/json-to-csv(有点支持python 3.4),这是完整的json-to-csv.py文件。如果我设置,转换工作正常

    #Base Condition
else:
    reduced_item[str(key)] = (str(value)).encode('utf8','ignore')
Run Code Online (Sandbox Code Playgroud)

fp = open(json_file_path, 'r', encoding='utf-8')
Run Code Online (Sandbox Code Playgroud)

但是当我将csv导入MS Excel时,我看到了西里尔字母错误的字符,例如\ xe0 \ xf1,英文文本就可以了。尝试设置encode('cp1251','ignore'),但随后出现错误UnicodeDecodeError:'charmap'编解码器无法解码位置Y的字节X:字符映射到(如此处UnicodeDecodeError:'charmap'编解码器无法解码位置Y的字节X:字符映射到<undefined>

import sys
import json
import csv

##
# This function converts an item like 
# {
#   "item_1":"value_11",
#   "item_2":"value_12",
#   "item_3":"value_13",
#   "item_4":["sub_value_14", "sub_value_15"],
#   "item_5":{
#       "sub_item_1":"sub_item_value_11",
#       "sub_item_2":["sub_item_value_12", "sub_item_value_13"]
#   }
# }
# To
# {
#   "node_item_1":"value_11",
#   "node_item_2":"value_12",
#   "node_item_3":"value_13",
#   "node_item_4_0":"sub_value_14", 
#   "node_item_4_1":"sub_value_15",
#   "node_item_5_sub_item_1":"sub_item_value_11",
#   "node_item_5_sub_item_2_0":"sub_item_value_12",
#   "node_item_5_sub_item_2_0":"sub_item_value_13"
# …
Run Code Online (Sandbox Code Playgroud)

python csv unicode json cyrillic

5
推荐指数
2
解决办法
2742
查看次数

Tweepy:使用Twitter搜索API可以获得旧推文吗?

根据http://www.theverge.com/2014/11/18/7242477/twitter-search-now-lets-you-find-any-tweet-ever-sent Twitter搜索现在可以让您找到任何发送过的推文.

但是,当我试图使用tweepy从2014年到2015年获取推文时,它只获得最近:

    query = 'Nivea'
    max_tweets = 1000
    searched_tweets = [json.loads(status.json) for status in tweepy.Cursor(api.search,
                                                                           q=query,
                                                                           count=100,
                                                                           #since_id="24012619984051000",
                                                                           since="2014-02-01",
                                                                           until="2015-02-01",
                                                                           result_type="mixed",
                                                                           lang="en"
                                                                           ).items(max_tweets)]
Run Code Online (Sandbox Code Playgroud)

我试过="2014-02-01",而且是_id但不管怎样.

python twitter json tweepy

5
推荐指数
1
解决办法
1万
查看次数

如何在基于Django类的视图中访问当前用户

我无法在基于Django类的视图中访问当前登录的用户:

models.py:

class Userproject(models.Model):
class Meta:
    verbose_name = u'pp'
    verbose_name_plural = u'pps'

user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="project", verbose_name=_("???????? ???????"))
#user = models.ForeignKey(User, unique=True)

name = models.TextField(u'???????? ???????', unique=True)
date_created = models.DateTimeField(u'???? ????????', default=datetime.now(), db_index=True)
date_until = models.DateTimeField(u'??????? ??', default=datetime.now(), db_index=True)
Run Code Online (Sandbox Code Playgroud)

views.py:

@login_required
class UserprojectList(ListView):
    context_object_name = 'userproject_list'
    queryset = Userproject.objects.filter(user=self.request.user)
    template_name = 'userproject_list.html'  
Run Code Online (Sandbox Code Playgroud)

当我导航到url时,我看到错误: 名称'self'未定义

如果我将self.request.user更改为request.user,则错误为:name'request '未定义

请注意,没有用户过滤视图正在工作并显示数据django 1.8.5

python django

5
推荐指数
2
解决办法
1万
查看次数