我有以下型号:
class Stop(models.Model):
name = models.CharField(max_length=50)
point = models.PointField()
objects = models.GeoManager()
Run Code Online (Sandbox Code Playgroud)
我想从北到南排序.我该怎么做呢?
Stop.objects.order_by('point')
他们从西向东排序.
谢谢.
这是我的完整模型:
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
class Stop(models.Model):
gtfs_stop_id = models.IntegerField(db_index=True, unique=True)
name = models.CharField(max_length=50)
point = models.PointField()
parkings = models.GeometryCollectionField(null=True, blank=True)
objects = models.GeoManager()
def get_absolute_url(self):
return reverse('core:stop', args=(self.id,))
def __str__(self):
return self.name
Run Code Online (Sandbox Code Playgroud) 我想在同一行上显示两个表单字段,而不是一个接一个。
目前,我得到:
Choice a theme :
. Datasystems
. Cameroun
Run Code Online (Sandbox Code Playgroud)
但我想显示这个表格,如:
Choice a theme:
. Datasystems . Cameroun
Run Code Online (Sandbox Code Playgroud)
我的.html 文件看起来像:
{% extends 'Base_Configurations.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}
<h3> <span class="glyphicon glyphicon-file"></span> Choix du thème DatasystemsEC </align> </h3>
{% endblock %}
{% block content %}
<form class="form" method='POST' action=''> {% csrf_token %}
<br></br>
{{ form }}
<br></br>
<input class="button" type="submit" value="Valider le thème" />
</form>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
我还有一个.css …
我正在尝试在Django中安装django-oauth2-provider.在安装和配置settings.py之后,在迁移期间,我收到的错误如下:
django.core.exceptions.AppRegistryNotReady:尚未加载应用.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'hello_api',
'rest_framework.authtoken',
'provider',
'provider.oauth2',
]
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',
#'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'hello_api2.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
Run Code Online (Sandbox Code Playgroud)
错误回溯:
error: File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/__init__.py", …
Run Code Online (Sandbox Code Playgroud) Django 新手,感觉我快要弄清楚我哪里出错了。我一直试图将上下文传递给我的模板,但无济于事。在模型中,我有:
class Rate(models.Model):
name = models.CharField(max_length = 140)
ratings = GenericRelation(Rating, related_query_name= 'object_list')
def __str__(self):
return self.id
Run Code Online (Sandbox Code Playgroud)
在视图中,
def RateList(request):
queryset = Rate.objects.filter(ratings__isnull=False).order_by('ratings__average')
context= {
"object_list": queryset,
"title": "List"
}
return render(request, 'UploadApp/upload.html', context)
Run Code Online (Sandbox Code Playgroud)
最后,在我的模板中,我{% ratings object_list %}
按照文档将 HTML 放入了 HTML 中。不确定我是否只是忽略了一些小细节,但是'str' object has no attribute 'meta'
当我尝试加载页面时出现错误。任何帮助表示赞赏,我在拉头发阶段
python django django-templates django-models django-queryset
<div class="gallery_re_form">
<form action="http://gall.dcinside.com/?/forms/comment_submit" method="post" accept-charset="utf-8" name="comment_write" id="comment_write" />
<div style="display:none">
<input type="hidden" name="ci_t" value="625752bb366f010c56e506e5d0f93822" />
</div>
<input type="hidden" name="ehqo_C" id="ehqo_C" value="spam_key" />
<input type="hidden" name="spam_key" id="spam_key" value="rhkdrhgkwlak!!" />
<input type="hidden" name="fb8f95190d2b70480acb309f91653d7e4416d4f99a0b67a0b866f06087fdec4588f68fe210675e74919d2ecc50e08f1fd6f75119" id="fb8f95190d2b70480acb309f91653d7e4416d4f99a0b67a0b866f06087fdec4588f68fe210675e74919d2ecc50e08f1fd6f75119" value="b9d3cc45576e30144d8f299fdc61356552989b3aba08238c811b1d3183a104cc2d1d3984af72c4f2eaa2738ca41819d05533731a" />
<input type="hidden" name="service_code" value="21ac6e96ad152e8f15a05b7350a24759b5606fa191c17e042e4d0175735f4c61d63153c3ce7b4eb89b565a7f6a04ad0667df75f39625ab6fe0816d23f4bed5387546b52d6874b5c201e54df7b5db9187219b048cffc9ef8a106febabfba125eff122df732d9cc52fcaae8b11c42ff5f6fd5ef81901df4103827e7233615992141c180be76852634d53b60c6f911ccdfc762b3db554d8ee36528547bceede30697120c5291acb255a" />
<br />
<div class="re_input">
<div>
<ul>
<li>
<input type="text" name="name" id="name" class="re_name re_in" onfocus="this.style.background='#FFFFFF'" title="nickname" />
</li>
<li>
<input type="password" name="password" id="password" class="re_pw re_in" onfocus="this.style.background='#FFFFFF'" title="password" />
</li>
</ul>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我正在尝试重写 google chrome 扩展。我想在此 HTML 响应中获取#spam_key
s …
我正在尝试从另一个 Django 应用程序中的一个 Django 应用程序导入一个类。
mainProjectFolder
|--__init__.py
|--manage.py
|--app1
|--__init__.py
|--class1.py
|--app2
|--__init__.py
|--anotherClass.py
|--mainProjectFolder
|--__init__.py
|--settings.py
...
Run Code Online (Sandbox Code Playgroud)
在app2.anotherClass.py
,我在做:
from mainProjectFolder.app1.class1 import Class1
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ImportError: No module named 'mainProjectFolder.app1'
Run Code Online (Sandbox Code Playgroud)
我在我注册的应用程序INSTALLED_APPS
中settings.py
的文件也是如此。
如果有任何不清楚的地方,请告诉我,我将编辑所需的内容。
很难使用jquery / ajax删除对象。我已经实现了一个表,该表的行包含约会模型中的对象列表。每行中都有一个删除按钮。
对象表的模板为:
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">ID</th>
<th>Patient Name</th>
<th>Day</th>
<th>Time</th>
<th>Location</th>
</tr>
</thead>
<tbody>
{% for appointment in appointments %}
<tr>
<td align="center">
<button class="delete_button" id="{{ appointment.id }}">
<em class="fa fa-trash"></em>
</button>
</td>
<td>1</td>
<td class="hidden" id="appointment_id">{{ appointment.id }}</td>
<td>{{ appointment.patient }}</td>
<td>{{ appointment.day }}</td>
<td>{{ appointment.time }}</td>
<td>{% if appointment.clinic %}
{{ appointment.clinic }}
{% endif %}
{% if appointment.hospital %}
{{ appointment.hospital }}
{% endif %}
</td>
</tr> …
Run Code Online (Sandbox Code Playgroud) 我正在使用旧的开源应用程序,每次尝试添加新的发票实例时,都会不断出现以下错误:
AttributeError at /admin/invoices/invoiceheaders/add/ 'tuple' object has no attribute 'startswith'
Run Code Online (Sandbox Code Playgroud)
我正在使用两(2)个模块:views.py和models.py:
views.py
@login_required
def new(request):
error = ''
if request.method == 'POST':
itemFound = False
for id in range(1, int(request.POST['numberitem']) + 1):
if request.POST.get('Item_%s' %id):
itemFound = True
break
if itemFound:
user = User.objects.get(id = request.user.id)
issuer = Contacts.objects.get(id = int(request.POST['Issuer']) )
customer = Contacts.objects.get(id = int(request.POST['Custumer']) )
payterm = Payterms.objects.get(id = int(request.POST['Payterm']) )
ihd = InvoiceHeaders()
ihd.user = user
ihd.issuer = issuer
ihd.payterm = payterm
ihd.customer = customer
ihd.status …
Run Code Online (Sandbox Code Playgroud) 我正在尝试做的事情:
每当他/她单击注销按钮时,我都会尝试注销用户。
我遇到了什么问题:
单击注销按钮时出现以下问题:
我的代码:-
文章.html:
<div class="container">
<nav class="nav blog-nav">
<a class="nav-link" href="#">Library</a>
{% if user.is_authenticated %}
<a style="float: right;" class="nav-link" href="{% url 'librarysystem:Logout' %}">Logout</a>
<a style="float: right;" class="nav-link" href="#">{{ request.user.username }}</a>
{% if user.UserProfile.avatar == None %}
<a style="float: right;" class="nav-link" href="#"><img class="img-thumbnail" src="/static/defaultPic/defaultPic.png" class="img-responsive" alt = "Generic placeholder thumbnail"/></a>
{% else %}
<a style="float: right;" class="nav-link" href="#" class="thumbnail"><img class="thumbnail" src="{{ request.user.UserProfile.avatar }}" class="img-responsive"/></a>
{% endif %}
{% endif %}
</nav>
</div>
Run Code Online (Sandbox Code Playgroud)
登录查看:
def loginUser(request):
data = {} …
Run Code Online (Sandbox Code Playgroud) django ×8
python ×6
html ×2
javascript ×2
ajax ×1
css ×1
geodjango ×1
importerror ×1
jquery ×1
oauth-2.0 ×1
python-2.7 ×1