小编w--*_*w--的帖子

django - 使用基本身份验证保护一些Web路径

我是django的新手,只是尝试了几个简单的实验来弄湿我的脚.我正在运行django 1.0,apache2 prefork和mod_wsgi.我正在尝试使用以下url结构构建一个站点

/
/members
/admin
Run Code Online (Sandbox Code Playgroud)

根基本上是一个公共区域.
应使用基本身份验证(可能由apache进行身份验证)保护成员路径,应
使用内置的django身份验证来保护管理路径.

按照文档中的示例,我基本上可以使用基本身份验证保护整个站点,但这不是我想要的.

除了虚拟主机配置:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

# Order allow,deny
# Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我指出正确的方向(或告诉我= P)如何使这成为可能?

谢谢


编辑:玩了一下我发现我可以做的事情:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias /members /django/rc/apache_httpauth/django.wsgi
<Directory /django/rc/apache_httpauth>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

</Directory>
Run Code Online (Sandbox Code Playgroud)

django.wsgi文件基本上是复制到另一个目录的同一文件,因此WSGIScriptAlias是不同的.这是hack-ish,但它有效..

有没有更好的方法来做我想做的事情?
这样做有什么缺点吗?

谢谢

django mod-wsgi basic-authentication django-admin

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

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

django-registration无法设置身份验证电子邮件的"发件人"电子邮件地址

我有django注册设置并使用我的应用程序.我在django 1.1上使用最新的django-registration,0.8 alpha.
如果它是相关的,我正在使用fcgi方法进行部署,并且django-registration应用程序部署在一个单独的文件夹中.我只是将包含文件夹添加到python路径.即在我的应用程序的settings.py中

import sys
sys.path.append('/path/to/django-registration-parent-folder')
Run Code Online (Sandbox Code Playgroud)

在我的设置文件中我也设置了

DEFAULT_FROM_USER = 'email@address.that.should.be used'
Run Code Online (Sandbox Code Playgroud)

然而,当django注册发送激活电子邮件时,它仍然是来自

站长@本地

我能够改变这种情况的唯一方法是改变django-registration里面的实际代码.即在models.py第254行:

# self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
self.user.email_user(subject, message, 'email@address.that.should.be used')
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我为什么在发送激活电子邮件时我的应用程序的设置文件中的DEFAULT_FROM_EMAIL没有被使用?

提前致谢

python django default django-registration

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

django rest框架嵌套的modelserializer

这是我的另一个问题
django-rest-framework,多模型继承,ModelSerializers和嵌套序列化

在django rest框架中我们可以像这样定义嵌套模型序列化器

class OtherModelSerializer(serializer.ModelSerializer):
    mybasemodel_set = MyBaseModelSerializer(many=True)

    class Meta:
        model = OtherModel
Run Code Online (Sandbox Code Playgroud)

当我们创建一个OtherModelSerializer时,MyBaseModelSerializer在__init__运行之前被实例化.我相信是这种情况,因为如果我覆盖__init__()MyBaseModelSerializer并检查"实例",则它是None.

我的问题是什么时候以及如何MyBaseModelSerializer通过查询集或实例mybasemodel_set

我的目标是覆盖我们这样做时发生的事情.

python django django-models django-queryset django-rest-framework

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

django 1.7rc3和芹菜3.13 - AppRegistryNotReady

这对我不起作用

$> cat/etc/lsb-release
DISTRIB_ID = Ubuntu
DISTRIB_RELEASE = 12.04
DISTRIB_CODENAME =精确
DISTRIB_DESCRIPTION ="Ubuntu 12.04.2 LTS"

django 1.7rc3
芹菜3.1.13
python 2.7

我试图跑

celery worker -A <project_name>
Run Code Online (Sandbox Code Playgroud)

我明白了

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Run Code Online (Sandbox Code Playgroud)

runserver命令工作正常,所以我不认为它与我的设置有关?

python manage.py runserver 0.0.0.0:8080
Run Code Online (Sandbox Code Playgroud)

我仔细检查了celery.py并确认它具有以下行的正确值:

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery('proj')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
Run Code Online (Sandbox Code Playgroud)

还有别的我应该做的吗?

python django celery

6
推荐指数
2
解决办法
1585
查看次数

zurb foundation - 许多重复的css条目

我一直在使用zurb奠定了一段时间.
我正在使用这里描述的bower + compass设置
http://foundation.zurb.com/docs/sass.html

今天工作时我注意到一个页面需要一段时间才能加载,并且在尝试解决问题时我注意到生成的css文件中有许多重复的指令.

我确定这可能是我做错了什么,但我不知道从哪里开始寻找,我甚至不知道提供哪些信息可能有助于缩小问题范围.

基础5.4.5 - >实际运行5.4.7

指南针1.0.1

任何帮助表示赞赏.

在此输入图像描述

***************更新:*****************
事实证明我实际上是在运行5.4.7我看了进去每个@Cartucho都有_functions.scss

看起来补丁就在那里:

// IMPORT ONCE
// We use this to prevent styles from being loaded multiple times for compenents that rely on other components. 
$modules: () !default;
@mixin exports($name) {
  $module_index: index($modules, $name);
  @if (($module_index == null) or ($module_index == false)) {
    $modules: append($modules, $name);
    @content;
  }
}
Run Code Online (Sandbox Code Playgroud)

@KatieK来自第90行的输出css的一些例子

/* line 386, ../../../../foundation_master/bower_components/foundation/scss/foundation/components/_global.scss */
*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
Run Code Online (Sandbox Code Playgroud)

在2885行

/* …
Run Code Online (Sandbox Code Playgroud)

css sass zurb-foundation compass-sass

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

Jest:如何使用 jest.genMockFromModule 的结果

我正在尝试模拟 firebase 模块

在我的__mocks__/firebase.js文件中我只是简单地输入

const mockFirebase = jest.genMockFromModule('firebase');
export default mockFirebase;
Run Code Online (Sandbox Code Playgroud)

在我的代码中如果我这样做

import * as firebase from 'firebase';
console.log(firebase);
Run Code Online (Sandbox Code Playgroud)

我明白了

{ default:
  {
    __esModule: true,
    initializeApp:
    { [Function: initializeApp]
      _isMockFunction: true,
      getMockImplementation: [Function],
      mock: [Getter/Setter],
      mockClear: [Function],
      mockReset: [Function],
      mockReturnValueOnce: [Function],
      mockReturnValue: [Function],
      mockImplementationOnce: [Function],
      mockImplementation: [Function],
      mockReturnThis: [Function],
      mockRestore: [Function] },
    app:
    { [Function: app]
      _isMockFunction: true,
      getMockImplementation: [Function],
      mock: [Getter/Setter],
      mockClear: [Function],
      mockReset: [Function],
      mockReturnValueOnce: [Function],
      mockReturnValue: [Function],
      mockImplementationOnce: [Function],
      mockImplementation: [Function],
      mockReturnThis: [Function],
      mockRestore: [Function], …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jestjs

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

世博独立应用程序:通知图标不显示显示

我有一个独立的 android 和 ios 应用程序。

目前正在android上测试推送通知。

我已经使用以下通知键设置了我的 app.json

"notification":{
      "icon": "./app_assets/icons/icon-48-gs.png",
      "color": "#000000"
    },
Run Code Online (Sandbox Code Playgroud)

上面的图标是一个具有透明度的 48x48 灰度图标。我也试过没有颜色属性。我在状态栏和实际通知中得到的只是一个白色/浅灰色/黑色方块。

仅灰色方块

在世博论坛中,我看到其他人提到他们使用 96x96 大小的图标解决了这个问题。这根本没有帮助。

https://forums.expo.io/t/push-notifications-missing-icon-on-android/9170

https://forums.expo.io/t/android-notification-status-bar-icon-too-small/7175

有人可以帮助提供有关问题可能是什么的指导吗?


根据下面@Raaj Nadar 的评论更新,这是我尝试过的图标。

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

react-native expo

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

django-model-utils:如果父模型/类是抽象的,那么InheritanceManager是否有效?

django-model-utils.我正在尝试文档中描述的InhertianceManager的基本使用.

nearby_places = Place.objects.filter(location='here').select_subclasses()
Run Code Online (Sandbox Code Playgroud)

唯一的区别是我的父模型/类是抽象的.这还有用吗?

我收到的错误就像

渲染时捕获DatabaseError:(1146,"Table'proj.ParentModel'不存在")

'Options'对象没有'_join_cache'属性

这两个都是当您尝试对抽象类进行查询时通常会遇到的错误.

在我的父模型中,我已经将经理定义如下:

class ParentModel(OrderedModel):
    objects = InheritanceManager()
Run Code Online (Sandbox Code Playgroud)

django django-models django-queryset

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

Django Admin:JSONField默认为空dict不会保存在admin中

在我的模型定义中

from django.contrib.postgres.fields import JSONField
.....
.......
.........

media_data=JSONField(default=dict)
Run Code Online (Sandbox Code Playgroud)

我创建了一个默认管理员

当我尝试保存而不接触该字段时,出现this field is required错误。

必填项

它看起来像一个表单验证问题,因为我可以以编程方式从代码中保存模型实例而不会出现问题。

为什么会这样呢?
我错过了一些愚蠢的事情吗?

python django django-models django-admin django-jsonfield

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