小编Pau*_* Bu的帖子

从整个git存储库中完全删除文件

使用git进行项目,我不小心添加了一个大.zip文件.在我开始将它上传到github之前我没有注意到.当我注意到,我打ctrl-c,git remove,git commit和(与文件未经跟踪现在)又上传了.

我知道这不是正确的选择,因为一旦我犯下了.zip它,它会一直保留在回购中,直到我恢复提交,但遗憾的是我没有.

现在,当有人试图从回购下载时,需要花费大量时间来完成它,有时候产量git the remote end hung up unexpectedly(我读过的可以通过做一些来解决git config)并且非常烦人.

我的观点是:有没有办法告诉在这个特定的提交版本中忘记这个特定文件的进一步拉/取请求?

git github git-commit

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

登录后django重定向不工作"下一步"不发布?

我有一个正常工作的登录页面,但重定向到引用页面除外.用户在应用程序中收到带有直接链接的电子邮件,他们(在此示例中)尚未登录并被重定向到登录页面.成功登录后,用户将被重定向到硬编码路径.见下面的例子.

电子邮件中的URL: http://localhost:8000/issueapp/1628/view/22

登录页面的URL: http://localhost:8000/login?next=/issueapp/1628/view/22

登录视图(带硬编码重定向):

def login_user(request):    
    state = "Please log in below..."
    username = password = ''

    if request.POST:
        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                state = "You're successfully logged in!"
                return HttpResponseRedirect('/issueapp/1628/')
            else:
                state = "Your account is not active, please contact the site admin."
        else:
            state = "Your username and/or password were incorrect."

    return render_to_response(
        'account_login.html',
        {
        'state':state,
        'username': username
        },
        context_instance=RequestContext(request)
    ) …
Run Code Online (Sandbox Code Playgroud)

python django next

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

如何获得用户权限?

我想检索用户的所有权限作为预设ID的列表,但是:

user.get_all_permissions()
Run Code Online (Sandbox Code Playgroud)

给我许可名称列表.怎么做?

python django django-authentication

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

git rebase - 继续没有变化

我有两个分支,有两个功能:banch_1branch_2. branch_2使用来自的功能branch_1.我所做的变化branch_1,并希望变基branch_2branch_1从中获取改变branch_1branch_2.

所以,我正在检查branch_2:

git checkout branch_2
Run Code Online (Sandbox Code Playgroud)

并尝试在branch_1上重新定义:

git rebase branch_1
Run Code Online (Sandbox Code Playgroud)

之后我得到两个文件的'合并冲突'.所以我跑了

git mergetool -t meld
Run Code Online (Sandbox Code Playgroud)

并解决这些冲突,从中选择更改branch_1.

我正在保存文件并转到终端,输入 git status并看到git索引没有变化.接下来,我跑git rebase --continue和获取

No changes - did you forget to use 'git add'? 
Run Code Online (Sandbox Code Playgroud)

错误.但没有什么可补充的!我键入git log并查看提交branch_1但没有提交branch_2.

我做错了什么?

git git-rebase

19
推荐指数
1
解决办法
5722
查看次数

QuerySet,Object没有属性id - Django

我正在尝试获取django中某些对象的id,但我不断收到以下错误异常值:QuerySet; 对象没有属性ID.我在views.py中的功能

@csrf_exempt  
def check_question_answered(request):
    userID = request.POST['userID']
    markerID = request.POST['markerID']
    title=request.POST['question']
    m = Marker.objects.get(id=markerID)
    u = App_User.objects.get(id=userID) 
    print userID
    print markerID
    print title
    # userID='1'
    # markerID='1'
    # title='Hello'
    at = AttachedInfo.objects.filter(attachedMarker=m.id, title=title)
    print 'user'
    print u.id
    print 'marker'
    print m.id
    print 'att'
    print at
    #print at.id
    if(Answer.objects.filter(marker=m.id, user=u.id, attachedInfo=at.id)):
        print 'pass'
        return HttpResponse('already answered')
    else:
        print 'not'
        return HttpResponse('not answered yet') 
Run Code Online (Sandbox Code Playgroud)

错误发生在此部分的if条件中(attachedInfo = at.id).我检查过,当我从条件中删除它时,一切都运行良好.

这是models.py

class AttachedInfo(models.Model):
    title = models.CharField(max_length=200)
    helpText = models.CharField(max_length=200, null=True, blank=True)
    type = models.CharField(max_length=200) …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-queryset django-views

16
推荐指数
3
解决办法
6万
查看次数

模型自依赖(一对多字段)实现

我想实现一个具有自我依赖性的模型.假设实例People_A可能依赖于People_B和People_C.我首先使用多对多关键实现此模型.

class People(models.Model):

dependency = models. ManyToManyField ('self', blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)

但结果是,如果People_A依赖People_B将导致People_B也依赖于People_A.这是我不想要的.

然后我用外键实现它.

class People(models.Model):

dependency = models.ForeignKey('self', blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)

但这也行不通.如果People_A依赖People_B,那么其他任何人都不能依赖People_B.它将涵盖具有最新依赖性的旧依赖项.

任何线索都会感激不尽

django one-to-many

12
推荐指数
1
解决办法
1886
查看次数

如何遍历模块的功能

导入foo.py后我有这个函数调用.Foo有几种我需要调用的方法,例如foo.paint,foo.draw:

import foo

code

if foo:
    getattr(foo, 'paint')()
Run Code Online (Sandbox Code Playgroud)

我需要使用while循环来调用和遍历所有函数foo.paint,foo.draw等.我该怎么做呢?

python functional-programming getattr

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

在Django中编写一个非常基本的搜索表单

所以我试图让事情变得非常简单.我想在搜索框中输入一个术语,并在结果页面上显示.

我的HTML表单是

<form method="get" action="/results/" class="navbar-form pull-right">
<input type="text" id="searchBox" class="input-medium search-query" name="q" placeholder="Search">
<input type="submit" class="btn" value="Search" >
</form>
Run Code Online (Sandbox Code Playgroud)

views.py看起来像这样:

def search(request):
    query = request.GET['q']
    t = loader.get_template('template/results.html')
    c = Context({ 'query': query,})
    return HttpResponse(t.render(c))
Run Code Online (Sandbox Code Playgroud)

最后,结果模板包含:

<div>You searched for: {{ query }} </div>
Run Code Online (Sandbox Code Playgroud)

这是urls.py

urlpatterns = patterns('',
url(r'^home/$', 'search.views.home'),
url(r'^results/$', 'search.views.results'),
Run Code Online (Sandbox Code Playgroud)

没有任何东西出现在这个{{ query }}空间里.

html python django search django-forms

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

语法错误和运行时错误有什么区别?

例如:

def tofloat(i): 
    return flt(i)

def addnums(numlist):
    total = 0
    for i in numlist:
        total += tofloat(i)
    return total

nums = [1 ,2 ,3]
addnums(nums)
Run Code Online (Sandbox Code Playgroud)

flt应该是float,但我很困惑无论是语法错误或运行时错误.

python syntax runtime dynamic

6
推荐指数
1
解决办法
5990
查看次数

如何在django中提供可下载的zip文件

我浏览了django文档,我发现这段代码允许您将文件呈现为附件

dl = loader.get_template('files/foo.zip')
context = RequestContext(request)
response = HttpResponse(dl.render(context), content_type = 'application/force-download')
response['Content-Disposition'] = 'attachment; filename="%s"' % 'foo.zip'
return response
Run Code Online (Sandbox Code Playgroud)

foo.zip文件是使用pythons zipfile.ZipFile().writestr方法创建的

zip = zipfile.ZipFile('foo.zip', 'a', zipfile.ZIP_DEFLATED)
zipinfo = zipfile.ZipInfo('helloworld.txt', date_time=time.localtime(time.time()))
zipinfo.create_system = 1
zip.writestr(zipinfo, StringIO.StringIO('helloworld').getvalue())
zip.close()
Run Code Online (Sandbox Code Playgroud)

但是当我尝试上面的代码来渲染文件时,我得到了这个错误

'utf8'编解码器无法解码位置10中的字节0x89:无效的起始字节

有关如何做到这一点的任何建议吗?

python django render file web

6
推荐指数
2
解决办法
6752
查看次数