小编suh*_*lvs的帖子

是否有可能使git跟踪空文件夹?

我从这篇文章中读到了解释为了使git跟踪文件夹,必须至少有一个空文件:

Currently the design of the Git index (staging area) only permits files 
to be listed and nobody competent enough to make the change to allow 
empty directories has cared enough about this situation to remedy it.

Directories are added automatically when adding files inside them. 
That is, directories never have to be added to the repository, 
and are not tracked on their own. You can say "git add <dir>" and it 
will add the files in there. …
Run Code Online (Sandbox Code Playgroud)

git

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

如何将“Tue Feb 25 2014 00:00:00 GMT+0530 (IST)”转换为python日期时间对象?

我对 dateformat 有一些疑问Tue Feb 25 2014 00:00:00 GMT+0530 (IST)

  • 确实Tue Feb 25 2014 00:00:00意味着GMTIST
  • 是否可以将其转换为 python datetime
  • 是否可以将其转换为DD-MM-YY,HH:MM:SSGMT 格式。

这是我尝试转换成的内容python datetime::

但当我尝试使用时出现错误%z

>>> time_format="%a %b %d %Y %H:%M:%S GMT%z (%Z)"
>>> v="Tue Feb 25 2014 00:00:00 GMT+0530 (IST)"
>>> mydate=datetime.strptime(v,time_format)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/_strptime.py", line 317, in _strptime
    (bad_directive, format))
ValueError: 'z' is a bad directive in …
Run Code Online (Sandbox Code Playgroud)

python timezone datetime python-datetime

4
推荐指数
1
解决办法
6602
查看次数

Django:通过外键字段的id进行查询的正确方法是什么?

我有两个models

class Organization(models.Model):
    title = models.CharField(max_length=100)

class Folder(models.Model):
    organization = models.ForeignKey("Organization",related_name='folders')
    title = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

现在我想过滤folderby organization id。所以我尝试了:

  • Folder.objects.filter(organization= 1)
  • Folder.objects.filter(organization_id= 1)
  • Folder.objects.filter(organization__id= 1)
  • Folder.objects.filter(organization__pk= 1)
  • Folder.objects.filter(organization= Organization.objects.get(id=1))

不管你相信与否,一切都会返回相同的结果。

那么有人知道通过外键字段的 id 进行查询的正确方法是什么吗?

更新

但是当尝试通过以下方式创建时folder

Folder.objects.create(organization__id=1,title='hello')
Run Code Online (Sandbox Code Playgroud)

出现错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/suhail/.virtualenvs/heybadges/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/suhail/.virtualenvs/heybadges/local/lib/python2.7/site-packages/django/db/models/query.py", line 370, in create
    obj = self.model(**kwargs)
  File "/home/suhail/.virtualenvs/heybadges/local/lib/python2.7/site-packages/django/db/models/base.py", line 452, in __init__
    raise TypeError("'%s' …
Run Code Online (Sandbox Code Playgroud)

django django-models

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

我想在混淆后重定向到<a>上的链接?

我有一个问题,我正在努力.我想href="/jobs/emp/del/?id={{ job.pk }}"在确认后重定向到链接.我在用bootboxjs

{% for job in jobs %}
<a class="btn deleteJob" href="/jobs/emp/del/?id={{ job.pk }}"</a> 
{% for job in jobs %}
Run Code Online (Sandbox Code Playgroud)

如何在执行链接之前要求确认/jobs/emp/del/?id={{ job.pk }}

我试过了:

<a class="btn deleteJob"><span style="display:none">/jobs/emp/del/?id={{ job.pk }}</span>
                            <i class="icon-trash"></i></a>
<script src="/static/js/bootbox.js" type="text/javascript"></script>
<script>

$('.deleteJob').click(function(){
    bootbox.confirm("Are you Sure want to delete!", function (x) {
    if (x){

        var link= $(this).find( $spans ).text();            
        document.location.href='/'+link+'/';}
    });        
});
</script>
Run Code Online (Sandbox Code Playgroud)

在一个大的for循环中,但它不起作用!?

html django jquery loops

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

如何在ubuntu中将celeryd作为守护进程运行?

我正在尝试安装init.d脚本,以运行celery来安排任务。当我尝试通过启动时sudo /etc/init.d/celeryd start,它会引发错误"User does not exist: 'celery'"

我的芹菜配置文件(/etc/default/celeryd)包含以下内容:

# Workers should run as an unprivileged user.
CELERYD_USER="celery"
CELERYD_GROUP="celery"
Run Code Online (Sandbox Code Playgroud)

我知道这些是错误的,这就是为什么它会引发错误。

文档只是说:

CELERYD_USER
User to run celeryd as. Default is current user.
Run Code Online (Sandbox Code Playgroud)

仅此而已。任何帮助将不胜感激。

python django initialization celery django-celery

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

Listivew Widget不会自动更新

我的朋友已完成一个应用程序,现在他为他的应用程序创建了一个小部件,可用于以列表视图方式显示任务列表.首先,当他拖动窗口小部件并安装在主屏幕时,它将正常工作,并以列表视图方式显示任务.

他的问题是,当他对他的应用程序进行更改然后回到他的主屏幕时,没有反映出任何变化.他正在使用onReceive()这个方法来更新小部件

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;

public class WidgetTaskSchedular extends AppWidgetProvider {
    private final String TAG = "CalendarViewSample:"
            + this.getClass().getName();

    SharedPreferences sharedprefer;

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        if(intent.getAction().equals("update_widget"))
        {
            int[] appid=new int[1];
            sharedprefer=context.getSharedPreferences("TaskWidget", 0);
            appid[0]=sharedprefer.getInt("widget_key",0);
            Log.i(TAG,"Appwidgetid"+appid[0]);
            onUpdate(context, AppWidgetManager.getInstance(context),appid);

        }
    }
    public static String EXTRA_WORD=
            "com.capsone.testing.calendar.WORD";
    @SuppressWarnings("deprecation")
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) …
Run Code Online (Sandbox Code Playgroud)

android widget auto-update

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

正则表达式匹配空字符串?

我想匹配和分组这些列出的任何单词:

aboutus/,race/,cruise/,westerlies/,weather/,reach/,gear/empty_string

这是一个解决方案,但与empty_string不匹配:

^(aboutus|race|cruise|westerlies|weather|reach|gear)/$
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:如何在此匹配中包含空字符串?

我仍然没有得到一个很好的解决方案.

所以我专门为empty_string添加了一个正则表达式:ie ^$.

注意:这些正则表达式适用于django urls.py.

更新:如果捕获组不包含,将会更好/

python regex django django-urls

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

将反应形式与模板形式混合

我已经使用模板表单构建了一个包含大量输入的大表单。现在,我有了一个动态添加一部分输入的要求。由于使用Reactive Form动态添加输入似乎更容易,因此我想将输入的特定部分更改为Reactive Form。

那么有可能在同一个表单标签中混合反应形式和模板形式吗?

angular angular-reactive-forms angular-template-form

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