小编alt*_*tic的帖子

没有名为'allauth.account.context_processors'的模块

我想使用Django-Allauth,所以我安装如下,它在我的笔记本电脑localhost中完美运行; 但是当我在我的服务器中拉它时,遇到以下错误:

No module named 'allauth.account.context_processors'
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

# Django AllAuth
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Already defined Django-related contexts here

                # `allauth` needs this from django
                'django.contrib.auth.context_processors.auth',
                'django.core.context_processors.request',

                # `allauth` specific context processors
                'allauth.account.context_processors.account',
                'allauth.socialaccount.context_processors.socialaccount',
                "django.contrib.auth.context_processors.auth",
                "django.core.context_processors.debug",
                "django.core.context_processors.i18n",
                "django.core.context_processors.media",
                "django.core.context_processors.static",
                "django.core.context_processors.tz",
                "django.core.context_processors.request",
                "moolak.context_processors.image",
            ],
        },
    },
]


AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such …
Run Code Online (Sandbox Code Playgroud)

python django packages django-settings django-allauth

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

使用模型继承和不可空字段错误计数

改模型后我在我的项目中使用了继承模型;但我给出了不可为空的字段错误。我该怎么办? 我正在使用 Django 1.7

class Questions(models.Model):
    question_category = models.ForeignKey(Course, blank=False)
    question_author = models.ForeignKey(Author, blank=False)
    question_details = models.CharField(max_length=100, blank=False, default='')
    timestamp = models.DateTimeField(auto_now_add=True)

class TypeFive(Questions):
    question_title = models.CharField(max_length=100, blank=False, default=generator(5), unique=True, editable=False)

    def __str__(self):
        return "{}".format(self.question_title)


class TypeFiveChoice(models.Model):
    question_choice = models.ForeignKey(TypeFive)
    is_it_question = models.BooleanField(default=False)
    word = models.CharField(default='', blank=False, max_length=20)
    translate = models.CharField(default='', blank=False, max_length=20)
    timestamp = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "{} : {}, {}".format(self.question_choice, self.word, self.translate)
Run Code Online (Sandbox Code Playgroud)

迁移后:

You are trying to add a non-nullable field 'questions_ptr' to typefive without a default; …
Run Code Online (Sandbox Code Playgroud)

python django inheritance django-models python-3.x

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

Semantic-UI:如何更改调光器背景颜色?

我想改变我模态调光器的颜色,但我不能!我该怎么办?

<div class="ui modal">
  <i class="close icon"></i>
  <div class="header">
    Profile Picture
  </div>
  <div class="content">
    <p>sth</p>
  </div>
  <div class="actions">
    <div class="ui black button">
      Nope
    </div>
    <div class="ui positive right labeled icon button">
      Yep, that's me
      <i class="checkmark icon"></i>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

在JS中:

我尝试了以下代码,但是,没有变化!

$('.ui.modal').each(function() {
    $(this).modal({allowMultiple: true}).modal('show').css('background-color', 'yellow');
});
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery semantic-ui

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

在ForeignKey上设置unique=True与使用OneToOneField具有相同的效果

我最近从 1.7 切换到 Django 1.8.2,但遇到了一些问题,例如在我的一个模型中:

class Author(models.Model):
    author = models.ForeignKey(UserProfile, blank=False, primary_key=True)
    timestamp = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

但是当我运行服务器时,我遇到以下警告:

WARNINGS:
exam.Author.author: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

python django django-models python-3.x django-1.8

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

为表的列"id"指定了多个默认值

我用我的笔记本电脑运行我的网站,它的数据库是Sqlite,最近我想把它转移到DigitalOcean,我把它的数据库更改为Postgresql,但是当我迁移时遇到了一些问题.

Python 3.4 Django 1.8

错误

django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "profiles_userprofile"
Run Code Online (Sandbox Code Playgroud)

我的模特

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    avatar = models.ImageField(blank=True, upload_to=get_image_path, default='/static/image/avatar/male.png')
    age = models.IntegerField(default=4, validators=[MinValueValidator(3), MaxValueValidator(99)])
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

python database django postgresql django-models

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

通过Django Template检测模板中使用的语言

是否有可能Django意识到模板中使用了哪种语言并改变了HTML方向的元素并对齐?例如,我希望有时在一个元素中使用波斯语,另一次我想在那里使用英语,这两个都是通过数据库获得的.另外我不想逐个操作每个元素; 我想要整个模板的通用解决方案.

<p style="direction: ltr">Hi!<p>
Run Code Online (Sandbox Code Playgroud)

有时:

<p style="direction: rtl">Hi!<p>
Run Code Online (Sandbox Code Playgroud)

python django html5 django-templates django-models

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

python如何用时间元素创建元组元组?

我想创建一个像这样的元组:

(('0', '00:00:00'), ('1', '00:30:00'), ('2', '00:01:00') ..., ('46', '23:00:00'), ('47', '23:30:00'))
Run Code Online (Sandbox Code Playgroud)

尝试:

lines = []
a = datetime.timedelta(minutes=0)
for ii in range (48):
    lines.append(a)
    a = a.timedelta(minutes=30)
Run Code Online (Sandbox Code Playgroud)

我试过各种各样的方法,但我真的不知道该怎么办?

python for-loop tuples python-datetime

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

为什么AngularJS控制器中的另一个变量会发生变化?

我有一个AngularJS控制器,如下所示:

schedule.controller('schedule', ['$scope', '$http', function($scope, $http){
    $http.get('/zt-api/business/admin/' + window.location.pathname.split('/')[2]).success(function(data){
        $scope.admin_times = data;
        $scope.admin_times_unix = data;
        $scope.weekDays = {'Saturday': "????", 'Sunday': "??????", 'Monday': "??????", 'Tuesday': "?? ????",
            'Wednesday': "????????", 'Thursday': "???????", 'Friday': "????"};
        angular.forEach($scope.admin_times, function (value, key) {
            angular.forEach(value, function (value2, key2) {
                angular.forEach(value2, function (value3, key3) {
                    angular.forEach(value3, function (value4, key4) {
                        angular.forEach(value4, function (value5, key5) {
                            var info = $scope.admin_times[key]["week_"+ key][key3].times[key5];
                            if (!isNaN(info)){
                                var myObj = $.parseJSON('{"date_created":"'+ $scope.admin_times[key]["week_"+ key][key3].times[key5] +'"}'),
                                myDate = new Date(1000*myObj.date_created);
                                $scope.admin_times[key]["week_"+ key][key3].times[key5] = myDate.toLocaleString().split(", ")[1] …
Run Code Online (Sandbox Code Playgroud)

javascript json getjson javascript-objects angularjs

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