小编Mar*_*ark的帖子

我想要make push并得到错误:src refspec master不匹配任何

我正在Heroku上主持.我想推动一下:

git push master Heroku
Run Code Online (Sandbox Code Playgroud)

我收到消息:

error: src refspec master does not match any.
error: failed to push some refs to 'git@heroku.com: etc ...'
Run Code Online (Sandbox Code Playgroud)

git hosting repository heroku

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

AttributeError:'module'对象没有属性'TestCase'

我有一个名为unittest的文件:test.py

我的代码:

import unittest

class Test(unittest.TestCase):

    def myTest(self):
        a = 1
        self.assertEqual(a, 1)


if __name__ == '__main__':
    unittest.main()
Run Code Online (Sandbox Code Playgroud)

当我按F5时,我收到一个错误:

Traceback (most recent call last):
  File "/home/mariusz/Pulpit/test.py", line 1, in <module>
    import unittest
  File "/home/mariusz/Pulpit/unittest.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'TestCase'
Run Code Online (Sandbox Code Playgroud)

python unit-testing assertions

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

Django Rest:视图不想导入

我正在使用Django教程Rest Framework进行练习(http://www.django-rest-framework.org/tutorial/1-serialization)

我正处于创建URL的阶段,我遇到了查看视图的问题.

我执行代码:

import snippets from views
Run Code Online (Sandbox Code Playgroud)

我无法导入视图,将收到:

'module' object has no attribute 'snippet_list'
Run Code Online (Sandbox Code Playgroud)

我的代码视图:

from .models import Snippet
from serializers import SnippetSerializer
from rest_framework.renderers import JSONPRenderer
from rest_framework.parsers import JSONParser
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

class JSONResponse(HttpResponse):

    def __init__(self, data, **kwargs):
        content = JSONPRenderer().render(data)
        kwargs['content_type'] = 'aplication/json'
        super(JSONPRenderer, self).__init__(content, **kwargs)

    @csrf_exempt
    def snippet_list(request):
        """
        List all code snippets or create new code snippet
        """
        if request.method == "GET":
            snippet = Snippet.objects.all()
            serializer = …
Run Code Online (Sandbox Code Playgroud)

python django import django-rest-framework

7
推荐指数
1
解决办法
1445
查看次数

InvalidRequestError: 实例 '&lt;User at 0x7f65938a7510&gt;' 未持久化

我想在框架 Flask 中执行这样的测试并得到消息:

InvalidRequestError: Instance '<User at 0x7f65938a7510>' is not persisted

  File "tests.py", line 31, in test_removeProfil
    db.session.delete(user)
Run Code Online (Sandbox Code Playgroud)

我的测试代码:

class TestCase(unittest.TestCase):

    def test_removeProfil(self):
        user = User(name="John", age=33, email="john@john.com")
        db.session.delete(user)
        db.session.commit()
        self.assertNotEqual(user.name, "John")
        self.assertNotEqual(user.age, 33)
        self.assertNotEqual(user.email, "john@john.com")
Run Code Online (Sandbox Code Playgroud)

python unit-testing flask

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

Flask中的分页不起作用

我有一个观点:

@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
@app.route('/index/<int:page>', methods=['GET', 'POST'])
def index(page=1):
    posts = Post.query.paginate(page, 3, False).items
    return render_template('index.html', posts=posts)
Run Code Online (Sandbox Code Playgroud)

代码模板:

    {% if posts %}
    <ol>
    {% for post in posts %}
        <li>{{ post.title }}</li>  | {{ post.text }} | {{ post.time }}</li>
    {% endfor %}
    </ol>
    {% else %}
    <h2>There is no posts</h2>
    {% endif %}

    {% if posts.has_prev %}<a href="{{ url_for('index', page=posts.prev_num) }}"><< Newer posts</a>{% else %}<< Newer posts{% endif %} |
    {% if posts.has_next %}<a href="{{ url_for('index', …
Run Code Online (Sandbox Code Playgroud)

python pagination flask flask-sqlalchemy

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

无法正常移动到其他页面

我有4个按钮.

其中三个正在展示许可证.其中一个名为"企业"的人必须转到另一页.

不幸的是,当我点击"企业"时,会显示许可证,然后页面会转到另一个页面.

我怎么做不传递代码来显示许可证,但立即传递给另一个页面?

我的代码:

$('input[title="enterprise"]').click(function(){
    window.location.href = "/contact";
});

$('input[type=button]').click(showLicence).each(function() {
    this.version = this.title;
    this.title = "Buy ";
    switch(this.version) {
        case 'basic':
            this.title += 'Basic';
            break;
        case 'standard':
            this.title += 'Standard';
            break;
        case 'business':
            this.title += 'Business';
            break;
    }
});
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

-1
推荐指数
2
解决办法
56
查看次数