小编Flo*_*eee的帖子

基于Django类的CreateView和UpdateView,具有多个内联表单集

我一直在尝试使用多个内联表单集来执行基于Django类的CreateView和UpdateView

CreateView工作正常,但UpdateView无法正常工作,如果有人尝试使用多个内联formset的UpdateView,任何人都试过请分享updateview代码片段.

# models.py
from django.db import models

class Recipe(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()

class Ingredient(models.Model):
    recipe = models.ForeignKey(Recipe)
    description = models.CharField(max_length=255)

class Instruction(models.Model):
    recipe = models.ForeignKey(Recipe)
    number = models.PositiveSmallIntegerField()
    description = models.TextField()


# forms.py
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from .models import Recipe, Ingredient, Instruction

class RecipeForm(ModelForm):
    class Meta:
        model = Recipe

IngredientFormSet = inlineformset_factory(Recipe, Ingredient, extra=0)
InstructionFormSet = inlineformset_factory(Recipe, Instruction, extra=0)


# views.py
from django.http import HttpResponseRedirect
from django.views.generic.edit import CreateView, UpdateView
from …
Run Code Online (Sandbox Code Playgroud)

django django-class-based-views

18
推荐指数
3
解决办法
2万
查看次数

如何使用Cargo以rlib和dylib的形式构建一个具有不同内容的库?

我想制作一个包含以下内容的项目:

  • 图书馆
  • C的绑定
  • 使用该库的可执行文件

目录结构,不包括临时文件和其他垃圾:

.
??? Cargo.toml
??? src
?   ??? c_bindings.rs // contains C bindings for library
?   ??? compression.rs
?   ??? const_data.rs
?   ??? hash.rs
?   ??? lib.rs // library
?   ??? main.rs // simple executable that uses library
??? target
    ??? debug
        ??? gost_stribog
        ??? libgost_stribog.rlib
Run Code Online (Sandbox Code Playgroud)

cargo build要这样做:

  • 构建将忽略的Rust库(rlib) c_bindings.rs
  • 将使用的C库(dylib) c_bindings.rs
  • 可执行文件

调试目录应为:

??? target
    ??? debug
        ??? gost_stribog
        ??? libgost_stribog.rlib
        ??? libgost_stribog.so
Run Code Online (Sandbox Code Playgroud)

我应该是什么Cargo.toml样?

rust rust-cargo

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

Django 登录错误:“尝试写入只读数据库”

我正在尝试在 CentOS 6 上设置 Apache(2.4,从源代码构建)+Django(1.8.12),但是当我尝试登录我的站点或创建用户或其他写入数据库的内容时,我收到错误:

尝试写入只读数据库

我已经尝试过:

  • 将 db 文件的所有者更改为apache用户(不起作用)
  • 更改权限:775、774、664 给出与上面相同的错误;666、776 给出:

无法打开数据库文件

  • 对 django 项目的整个文件夹执行相同的操作

我遵循了这个教程。

我的 httpd.conf (我添加的部分):

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /var/www/project/project/wsgi.py
WSGIPythonPath /var/www/project:/var/www/env/lib/python3.5/site-packages

<Directory /var/www/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Run Code Online (Sandbox Code Playgroud)

./manage createsuperuser工作正常,用户已添加到数据库。

为了提供媒体服务,我使用 Nginx(所有媒体和静态文件都能正确检索)。

UPD

完整回溯:

Environment:


Request Method: POST
Request URL: http://localhost:8080/accounts/login/

Django Version: 1.8.12
Python Version: 3.5.1
Installed Applications:
('bootstrap3',
 'django_admin_bootstrapped',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'macros',
 'django_ajax',
 'ckeditor',
 'accounts',
 'main',
 'tutor',
 'public_testing',
 'control_testing', …
Run Code Online (Sandbox Code Playgroud)

python apache sqlite django centos

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