Python django建议不要运行crontab
我已经在设置中设置了推荐任务CRONTAB={'minute':'*/1'},所以应该每1分钟重复一次。 而且它不起作用, 任何使用过这个软件包的人 能告诉我我做错了什么吗 这是我的模型Python django建议不要运行crontab,python,django,Python,Django,我已经在设置中设置了推荐任务CRONTAB={'minute':'*/1'},所以应该每1分钟重复一次。 而且它不起作用, 任何使用过这个软件包的人 能告诉我我做错了什么吗 这是我的模型 # models.py from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import User from django.contrib.sites.model
# models.py
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Product(models.Model):
"""A generic Product"""
name = models.CharField(blank=True, max_length=100)
sites = models.ManyToManyField(Site)
def __str__(self):
return self.name
@models.permalink
def get_absolute_url(self):
return ('product_detail', [self.id])
def sites_str(self):
return ', '.join([s.name for s in self.sites.all()])
sites_str.short_description = 'sites'
@python_2_unicode_compatible
class Vote(models.Model):
"""A Vote on a Product"""
user = models.ForeignKey(User, related_name='votes')
product = models.ForeignKey(Product)
site = models.ForeignKey(Site)
score = models.FloatField()
def __str__(self):
return "Vote"
这是我的建议
# recommendations.py
from django.contrib.auth.models import User
from recommends.providers import RecommendationProvider
from recommends.providers import recommendation_registry
from .models import Product, Vote
class ProductRecommendationProvider(RecommendationProvider):
def get_users(self):
return User.objects.filter(is_active=True, votes__isnull=False).distinct()
def get_items(self):
return Product.objects.all()
def get_ratings(self, obj):
return Vote.objects.filter(product=obj)
def get_rating_score(self, rating):
return rating.score
def get_rating_site(self, rating):
return rating.site
def get_rating_user(self, rating):
return rating.user
def get_rating_item(self, rating):
return rating.product
recommendation_registry.register(Vote, [Product], ProductRecommendationProvider)
这是settings.py
"""
Django settings for smartTutor project.
Generated by 'django-admin startproject' using Django 1.10.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'qe+s3uemj302lc3ea-=54(6c9qxj2%ws2jq)(48=a__*bg+um_'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'bootstrapform',
'el_pagination',
'markdown_deux',
'pagedown',
'simpleblog',
'myProfile',
'chartkick',
'quiz',
'recommends',
'recommends.storages.djangoorm',
'myrec'
]
import chartkick
STATICFILES_DIRS = (
chartkick.js(),
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'smartTutor.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
WSGI_APPLICATION = 'smartTutor.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_env' , 'static_root')
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static_files') ]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_env' , 'media_root')
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
SITE_ID = 1
RECOMMENDS_TASK_CRONTAB = {'minute': '*/1'}
只是通过文档检查,我认为缺少某种类型的触发器(实际上,它应该由Django芹菜配置,而不是由Django推荐) 简易解决方案 使用crontab,而不是Django芹菜。您的crontab应该调用命令
python manage.py\u precomputer
如果您不知道如何创建crontab,请检查
然后,添加以下内容:***python/path/to/smartTutor/manage.py\u precompute
(Django的crontab示例)
芹菜溶液
如果你需要芹菜,我建议你检查一下
警告(已解决)
您正在使用Django 1.10,但它对我不起作用。我降级到Django 1.9进行测试(更多信息,我只是添加了一个)
已编辑
Django 1.10的问题已解决。谢谢,我将Django降级为1.8,python manage.py建议\u预计算工作,但crontab仍不工作如果您运行完整命令
python/path/to/smartTutor/manage.py建议\u预计算工作吗?如果您正在使用virtualenv,请检查。