我是多语言数据的新手,我的承认是我以前从未尝试过.目前我正在开发一个多语言网站,但我不知道将使用哪种语言.
我应该使用哪种校对/字符集来实现这一目标?
我应该使用某种Unicode类型的字符集吗?
当然,这些语言不属于这个世界,这些语言必须在我们主要使用的集合中.
urls.py
url(r'^(?i)(?P<slug>[a-zA-Z0-9_]+)$', views_search.index, name='articles'),
Run Code Online (Sandbox Code Playgroud)
context_processor.py
def get_username(request, **kwargs):
print kwargs
slug = kwargs.get('slug')
return {
'slug': slug
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它打印空字典并且没有任何内容返回到模板.我在设置中的模板上下文处理器中添加了这个.我怎么能在这里访问kwargs?
我想在不同的virtualenv中运行两个不同的django_projects.这是代码:
ServerName ubuntu_server_apache
<VirtualHost *:80>
ServerName dev.hexxie.com
ErrorLog "/home/ashish/deployments/mysite_dev/conf/mysite_dev_error.log"
WSGIScriptAlias / /home/ashish/deployments/mysite_dev/mysite/mysite/wsgi.py
Alias /static /home/ashish/deployments/mysite_dev/static_root
<Directory /home/ashish/deployments/mysite_dev/static_root>
Require all granted
</Directory>
Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>
<Directory /home/ashish/deployments/mysite_dev/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
WSGIPythonPath /home/ashish/deployments/mysite_dev/mysite:/home/ashish/.virtualenvs/mysite_dev/lib/python2.7/site-packages
<VirtualHost *:80>
ServerName hexxie.com
ServerAlias *.hexxie.com
ErrorLog "/home/ashish/deployments/mysite_prod/conf/mysite_error.log"
WSGIScriptAlias / /home/ashish/deployments/mysite_prod/mysite/mysite/wsgi.py
Alias /static /home/ashish/deployments/mysite_prod/static_root
<Directory /home/ashish/deployments/mysite_prod/static_root>
Require all granted
</Directory>
Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>
<Directory /home/ashish/deployments/mysite_prod/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AJAX创建网站导航.我有导航菜单,其中包含指向不同视图的链接({% url name %}
在模板中使用).我想要做的是使用AJAX加载页面内容.我尝试加载的页面内容包含在内容块({% block content %}
)中.
我也找到了这个片段http://djangosnippets.org/snippets/942/,但我想使用我已定义的视图,只使用ajax获取内容.
有什么建议?
我正在使用Angularjs及其$ http模块向Django服务器发送POST AJAX请求.这是一个例子:
$http({
method: 'POST',
url: '/url/',
data: 'test data'
}).
success(function(data, status, headers, config) {
doSomeStuffWhenSuccess();
});
Run Code Online (Sandbox Code Playgroud)
问题是我在Django中得到的.无论我发送什么数据始终是QueryDict
对象的关键,因此值始终是空列表.
<QueryDict: {u'test data': [u'']}>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么.我错过了什么?
我使用几乎默认创建的Django应用程序只使用默认中间件.我只创建了一个视图并在url config中设置了一个url.Django的版本是1.3.我配置angular的$ http模块总是发送一个包含csrf令牌的头来满足Django.
我正在使用Django和Django Rest Framework.如何验证发布到django rest framework api的图像的图像大小?
这有点令人困惑:
FILE_UPLOAD_MAX_MEMORY_SIZE = #something
将上载到内存的文件的最大大小(以字节为单位).大于FILE_UPLOAD_MAX_MEMORY_SIZE的文件将流式传输到磁盘.默认为2.5兆字节.
我将其设置为255,即使这样我也可以从django admin上传2MB图像.如果图像大小大于5MB,我想拒绝POST请求并引发错误
我正在 Django 中提交一个 ajax 表单并使用
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
Run Code Online (Sandbox Code Playgroud)
获取 csrf_token。该表单在 chrome 中运行良好。但是在 Firefox 中, csrf_token 的值为 null 并且给出了 403 禁止错误。当我在控制台中检查 cookie 时,我没有在控制台中收到 csrf_token。为什么 django 没有将 csrf_token 提供给 firefox 浏览器?
我正在使用django-easy-pjax制作单页应用程序:
base.html:
{% load staticfiles %}
<script type="text/javascript" src="{% static '/static/js/jquery.js' %}"></script>
<script src="{% static '/static/js/jquery.pjax.js' %}"></script>
{% block side%}
It is {% now "c" %}
<br><br>
<a href="/uu/">Next Page</a>
<br/></br>
{%endblock side%}
{%block main%}
{%endblock main%}
Run Code Online (Sandbox Code Playgroud)
1.html:
{% extends "base.html"|pjax:request %}
{%block main%}
If time doesnot change Easy pjax is working
{%endblock main%}
Run Code Online (Sandbox Code Playgroud)
views.py:
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.response import TemplateResponse
def index(request):
return render_to_response('base.html', {}, context_instance = RequestContext(request))
def …
Run Code Online (Sandbox Code Playgroud) 我想使用queryset迭代器来迭代大型数据集。Django提供iterator()
了此功能,但是每次迭代都会命中数据库。我发现以下代码可以进行大块迭代-
def queryset_iterator(queryset, chunksize=1000):
'''''
Iterate over a Django Queryset ordered by the primary key
This method loads a maximum of chunksize (default: 1000) rows in it's
memory at the same time while django normally would load all rows in it's
memory. Using the iterator() method only causes it to not preload all the
classes.
Note that the implementation of the iterator
does not support ordered query sets.
'''
pk = 0
last_pk = queryset.order_by('-pk').values_list('pk', flat=True).first()
if last_pk …
Run Code Online (Sandbox Code Playgroud) I am trying to use AzureStorage to for connecting azure storage with django 1.7 app .
models.py
from django.db import models
from myproject.storage import AzureStorage
class MyModel(models.Model):
my_file = models.FileField(upload_to="files", storage=AzureStorage(container="media"))
my_image = models.ImageField(upload_to="images", storage=AzureStorage(container="media"))
Run Code Online (Sandbox Code Playgroud)
But when I try to makemigrations I am getting :
ValueError: Cannot serialize: <myproject.storage.AzureStorage object at 0x7f85185e66d0>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing
Run Code Online (Sandbox Code Playgroud)
What exactly its not able to serialize ?
我正在尝试使用表单验证在django admin中验证图像.
models.py
class website_index(models.Model):
screenshot=models.ImageField(storage=AzureStorage(container="media"),upload_to='search/resources/screenshots/',blank=True,null=True)
Run Code Online (Sandbox Code Playgroud)
admin.py
class CustomIndexModelForm(forms.ModelForm):
class Meta:
model = website_index
fields = '__all__'
def clean_image(self):
screenshot = self.cleaned_data.get['screenshot']
if screenshot:
w, h = get_image_dimensions(screenshot)
if w!=h :
raise forms.ValidationError('Upload a square image')
return screenshot
def __init__(self, *args, **kwargs):
super(CustomIndexModelForm, self).__init__(*args, **kwargs)
self.fields['parent_id'].queryset = cat_tree.objects.exclude(level=0)
class website_index_Admin(admin.ModelAdmin):
form = CustomIndexModelForm
Run Code Online (Sandbox Code Playgroud)
我已经看到了其他答案,我正在确保这些点,当我上传违反验证规则的图像时,django仍未提出任何验证错误.
django ×10
python ×6
pjax ×2
ajax ×1
angularjs ×1
apache ×1
api ×1
azure ×1
django-admin ×1
django-csrf ×1
django-forms ×1
firefox ×1
http ×1
multilingual ×1
mysql ×1
rest ×1
unicode ×1
validation ×1
virtualhost ×1