根据Heroku网站,当我收到错误H14"No Web Processes Running"时,这是因为我需要通过以下方式扩展dynos:
heroku ps:scale web=1
但是,当我这样做时,我收到以下错误:
Scaling web processes... failed
! No such type as web
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?我想恢复我的网站!
当我跑步时,heroku ps
我什么也看不见.
更新:它没有检测到我的Procfile.我没有显式的Procfile,并且之前没有使用过...这是绝对必要的吗?
以下是我的表格:
class AdvancedSearchForm(forms.Form):
valueofres = forms.ChoiceField (label="res", choices = ((0, 0),(2.2, 2.2)), required= False)
Run Code Online (Sandbox Code Playgroud)
以下是我的观点:
def advancedsearch(request):
if request.method == "POST":
search = AdvancedSearchForm(request.POST, request.FILES)
if search.is_valid():
new_search = search.save(commit=False)
Run Code Online (Sandbox Code Playgroud)
我收到错误'AdvancedSearchForm' object has no attribute 'save'
......为什么?
我是正则表达式的新手,但是我希望匹配一个字符串,直到数字开始.
所以说我有:
EEEE1234
那我想只提取:
EEEE
我试过搜索,但我发现正则表达式令人困惑,我认为最好的方法是通过例子.有什么想法吗?此外,任何有关任何正则表达式代码生成器或良好的教程的见解?
我正在使用Django-Smuggler将JSON数据上传到我的数据库.
当我加载JSON文件时,我收到错误: No JSON object could be decoded
我使用在线JSON验证器来确保数据是有效的.我通过执行数据转储获得了这些数据.
任何人都知道为什么会这样吗?
这是异常被提出(加星标)的地方:
try:
for format, stream in data:
objects = serializers.deserialize(format, stream)
for obj in objects:
model = obj.object.__class__
if router.allow_syncdb(using, model):
models.add(model)
counter += 1
obj.save(using=using)
if counter > 0:
sequence_sql = connection.ops.sequence_reset_sql(style, models)
if sequence_sql:
for line in sequence_sql:
cursor.execute(line)
**except Exception, e:**
transaction.rollback(using=using)
transaction.leave_transaction_management(using=using)
raise e
Run Code Online (Sandbox Code Playgroud)
这里是我的JSON文件的一般格式:
[
{
"pk": 1,
"model": "auth.message",
"fields": {
"message": "Successfully uploaded a new avatar.",
"user": 1
}
},
{
"pk": 2, …
Run Code Online (Sandbox Code Playgroud) 我最近从1.2更新到Django 1.4.
在转换过程中,不推荐使用set_messages,现在消息API已更改为add_message.基于此页面,我应该使用以下格式:
messages.add_message(request, messages.INFO, 'Hello world.')
但是,我收到了错误global name 'request' is not defined
.谁知道为什么?
这是我的代码(以粗体显示问题的行)
class InviteFriendForm(UserForm):
to_user = forms.CharField(widget=forms.HiddenInput)
message = forms.CharField(label="Message", required=False, widget=forms.Textarea(attrs = {'cols': '20', 'rows': '5'}))
def clean_to_user(self):
to_username = self.cleaned_data["to_user"]
try:
User.objects.get(username=to_username)
except User.DoesNotExist:
raise forms.ValidationError(u"Unknown user.")
return self.cleaned_data["to_user"]
def clean(self):
to_user = User.objects.get(username=self.cleaned_data["to_user"])
previous_invitations_to = FriendshipInvitation.objects.invitations(to_user=to_user, from_user=self.user)
if previous_invitations_to.count() > 0:
raise forms.ValidationError(u"Already requested friendship with %s" % to_user.username)
# check inverse
previous_invitations_from = FriendshipInvitation.objects.invitations(to_user=self.user, from_user=to_user)
if previous_invitations_from.count() > 0:
raise …
Run Code Online (Sandbox Code Playgroud) 我有以下一点HTML:
<ul class="unstyled" style="font-size:16px;">
{% if stuff %} {% for eachthing in stuff %}
<li>
<a href = "path"> Stuff goes here </a>
</li>
{% endfor %} {% else %}
</ul>
Run Code Online (Sandbox Code Playgroud)
基本上我想改变模板中链接的文本颜色而不是CSS.
我该怎么做?我已经尝试为元素和元素添加'color'属性,但无济于事.
根据此文档,我应该能够在我的 Django 对象变量上使用查询集“_contains”来过滤我的结果
但是当我实现这段代码时:
cookbooks = Books.objects.filter (category_contains = 'cooking')
我收到以下错误:
Cannot resolve keyword 'category_contains' into field. Choices are: category, adder, date etc.
为什么会这样?我还看到了这个 StackOverflow 问题,有人解释说只使用变量category
意味着category_exact
. 但是如果我写category_exact
我会得到类似的错误。
我登录到 Heroku 服务器中我的应用程序目录:
Heroku run bash -app appname
Run Code Online (Sandbox Code Playgroud)
然后我删除了我的数据库:
Rm -r dev.db
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试同步我的数据库时,它不会创建新表。当我进入生产站点时,它仍然拥有所有数据库内容并让我登录等。
对我做错了什么有任何见解吗?我想完全重新创建数据库。
注意:我有一个 Django 应用
更新:这是我的数据库设置
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3", # Add "postgresql_psycopg2", "postgresql", "mysql", "sqlite3" or "oracle".
"NAME": PROJECT_ROOT + os.sep + "dev.db", # Or path to database file if using sqlite3.
"USER": "", # Not used with sqlite3.
"PASSWORD": "", # Not used with sqlite3.
"HOST": "", # Set to empty string for localhost. Not used with sqlite3.
"PORT": "", # Set to …
Run Code Online (Sandbox Code Playgroud) 我有一个名为“多对多”的字段categories
,我想获取存储在该字段中的不同值。
以下是我的模型:
class Book (models.Model):
categories=models.ManyToManyField(Category, related_name = 'categories', blank = True, null=True)
Run Code Online (Sandbox Code Playgroud)
这是我的类别模型:
class Category (MPTTModel):
category = models.CharField(max_length=250)
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
Run Code Online (Sandbox Code Playgroud)
我想获得与一本书相关的每个类别。我该怎么做?
只是说我在Python中有一个整数,例如:100.
我想把这个整数转换成一个数到这个整数的列表,例如:[1,2,3,... 100]
最有效的方法是什么?
(如果您想知道我为什么要这样做,那是因为我想使用的Django Paginate库需要一个列表 - 如果有更优雅的方式使用Paginate而不这样做,请告诉我).
我有一个for循环遍历一个文本文件(在这种情况下实际上是一个Python文件),它试图提取所有函数(寻找单词def
).一旦找到该单词,它就开始记录行,直到它到达一个空白区域(我用来表示该函数的结束).
我的问题是,我想在备份def
文件后备份,并记录在函数之前可能出现的任何注释.例如:# This function does the following...
等我要备份,直到我不再打哈希.
我怎么会用我写过的这个循环向后看?
for (counter,line) in enumerate(visible_texts):
line= line.encode('utf-8')
# if line doesn't contain def then ignore it
if "def" in line and infunction== 0:
match = re.search(r'\def (\w+)', line.strip())
line = line.split ("def")[1]
print "Recording start of the function..."
# Backup to see if there's any hashes above it (until the end of the hashes) ** how do I do this **
Run Code Online (Sandbox Code Playgroud)
我最后想要的输出示例是:
# This function was created …
Run Code Online (Sandbox Code Playgroud) 我添加了javascript来检测单击链接的时间,这是正常的,但是现在链接不起作用(即,它们不会将用户带到链接页面).
HTML:
<div class="designflow" style="padding-left:50px;padding-right:0px;padding-top:0px;padding-bottom:15px;margin-top:0px;float:left; font-size:18px; color: gray; height:150px; width:150px;margin-left:auto;margin-right:auto;display:inline-block;">
<a href = "/manufacturing/" class = "designflow" id = "manufacturing">
<img src="{{STATIC_URL}}pinax/images/manufacturing.png" width = "150px" style=margin-bottom:0px;" alt=""><br>
<p style="position:absolute;bottom:25px;padding-left: 0px; padding-right:0px; width:150px;text-align:center;">Manufacturing</p></a>
</div>
Run Code Online (Sandbox Code Playgroud)
JQUERY:
jQuery( 'div.designflow a' )
.click(function() {
do_the_click( this.id );
return false;
});
function do_the_click( designstage )
{
alert(designstage);
}
Run Code Online (Sandbox Code Playgroud) 我想添加通过链接和社交媒体共享特定模型对象的功能,就像单击share
下面的链接时 Stack Overflow 所做的那样。我喜欢它从页面中弹出的方式,就像带有链接一样。
Django 是否有一个模块可以执行类似的功能。
谢谢!