小编Chr*_*ris的帖子

带有redux-saga的无限循环

我正在使用react-router v4和redux-saga.我正在尝试在页面加载时进行API调用.当我访问时/detailpage/slug/,我的应用程序似乎陷入循环并且无休止地调用我的API端点.这是我的应用程序的设置方式.假设我的导入是正确的.

index.js

const history = createHistory()
const sagaMiddleware = createSagaMiddleware()
const middleware = [routerMiddleware(history), sagaMiddleware]

const store = createStore(
  combineReducers({
    aReducer
  }),
  applyMiddleware(...middleware)
)

injectTapEventPlugin();
sagaMiddleware.run(rootSaga)


ReactDOM.render(
  <Provider store={store}>
  <ConnectedRouter history={history}>
    <Switch>
      <Route path="/" exact component={HomePage} />
      <Route path="/detailpage/:slug" component={Detail} />
      <Route path="/page" component={Page} />
    </Switch>
  </ConnectedRouter>
  </Provider>,
  document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)

减速器/ index.js

const aReducer = (state={}, action) => {
  switch(action.type) {
    case 'SHOW_DETAIL':
    console.log('Reducers: reducer called')
    return Object.assign({}, state, { name: 'adfsdf' })
  default:
    return state;
  } …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-redux react-router-v4

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

使用Django 1.7迁移的Python 2.7未绑定方法

我正在升级到Django 1.7.4并使用新的内置迁移,但在尝试运行时出现以下错误makemigrations:

ValueError: Could not find function upload_callback in app_utils.
Please note that due to Python 2 limitations, you cannot serialize unbound 
method functions (e.g. a method declared and used in the same class body). 
Please move the function into the main module body to use migrations.For more information, 
see https://docs.djangoproject.com/en/1.7/topics/migrations/#serializing-values
Run Code Online (Sandbox Code Playgroud)

我的模型定义:

class Discount(models.Model):
    banner = models.ImageField(
        help_text=_("Banner image for this discount"),
        upload_to=upload_to('discounts/', 'title'),
        blank=True,
        null=True
    )
Run Code Online (Sandbox Code Playgroud)

我的上传回调app_utils.py:

def upload_to(path, attribute=None):
    def upload_callback(instance, filename):
        compact = …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-south python-2.7

4
推荐指数
1
解决办法
1042
查看次数