zoukankan      html  css  js  c++  java
  • 网站开发记录

    配置coding的git

    git init
    git remote add origin <git项目地址>
    git pull <git项目地址>
    git add .

    问题:
    我错误的使用了下面的命令添加了文件:
    git add myfile.txt
    
    现在我还没有运行git commit命令。有办法撤销它,从而不让这些文件包含到commit中吗?
    高票答案1:
    你寻找的是这个:
    git rm --cached <added_file_to_undo>
    git rm -r --cached .
    好了,我们现在回到了刚开始的地方。下一次我要使用-n参数来做一次预演,看看什么将会被添加进去:
    
    git add -n .
    

      


    git commit

    git push origin master 

    老是报hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    git push origin master  -f

    加了-f选项强制推送就好了

    安装模块

    #D:python35Scriptspip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple django
    #
    #D:python35Scriptspip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple django-allauth


    运行模块
    #D:python35python.exe D:python35Scriptsdjango-admin.py startproject web
    cd到项目目录web下,执行下面的语句
    #D:python35python.exe D:python35Scriptsdjango-admin.py startapp login
    #D:python35python.exe manage.py migrate
    #D:python35python.exe manage.py runserver 9999

    1.删除models.py
    无论是删除一个单独的model还是删除整个App,都需要首先删除models.py文件中的模型。

    确认没有其他文件引用models.py中的类。
    迁移或者删除你的数据库,Django提供了简便的方法方便用户删除某App下的所有数据(Django 1.7)。

    ./manage.py migrate your_app_name zero
    1
    删除models.py中的数据模型。
    2.删除App
    再次确认其他App中没有引用此App的文件
    删除整个App文件夹
    在settings.py的Installed Apps中移除该app。
    在urls.py中移除该App相关内容。
    3.REFRENCE

    创建用户数据库

    https://docs.djangoproject.com/zh-hans/2.1/intro/tutorial02/

    from django.contrib import admin
    from django.urls import include, path
    
    urlpatterns = [
        path('polls/', include('polls.urls')),
        path('admin/', admin.site.urls),
    ]
    

    函数 include() 允许引用其它 URLconfs。每当 Django 遇到 :func:~django.urls.include 时,它会截断与此项匹配的 URL 的部分,并将剩余的字符串发送到 URLconf 以供进一步处理。

    我们设计 include() 的理念是使其可以即插即用。因为投票应用有它自己的 URLconf( polls/urls.py ),他们能够被放在 "/polls/" , "/fun_polls/" ,"/content/polls/",或者其他任何路径下,这个应用都能够正常工作。

    何时使用 include()

    当包括其它 URL 模式时你应该总是使用 include() , admin.site.urls 是唯一例外。

    
    

    在你刚刚创建的 templates 目录里,再创建一个目录 polls,然后在其中新建一个文件 index.html 。换句话说,你的模板文件的路径应该是 polls/templates/polls/index.html 。因为 Django 会寻找到对应的 app_directories ,所以你只需要使用 polls/index.html 就可以引用到这一模板了。

    模板命名空间

    虽然我们现在可以将模板文件直接放在 polls/templates 文件夹中(而不是再建立一个 polls 子文件夹),但是这样做不太好。Django 将会选择第一个匹配的模板文件,如果你有一个模板文件正好和另一个应用中的某个模板文件重名,Django 没有办法 区分 它们。我们需要帮助 Django 选择正确的模板,最简单的方法就是把他们放入各自的 命名空间 中,也就是把这些模板放入一个和 自身 应用重名的子文件夹里。

    将下面的代码输入到刚刚创建的模板文件中:

    polls/templates/polls/index.html
    {% if latest_question_list %}
        <ul>
        {% for question in latest_question_list %}
            <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
    

    然后,让我们更新一下 polls/views.py 里的 index 视图来使用模板:

    polls/views.py
    from django.http import HttpResponse
    from django.template import loader
    
    from .models import Question
    
    
    def index(request):
        latest_question_list = Question.objects.order_by('-pub_date')[:5]
        template = loader.get_template('polls/index.html')
        context = {
            'latest_question_list': latest_question_list,
        }
        return HttpResponse(template.render(context, request))

    from django.shortcuts import render
    
    from .models import Question
    
    
    def index(request):
        latest_question_list = Question.objects.order_by('-pub_date')[:5]
        context = {'latest_question_list': latest_question_list}
        return render(request, 'polls/index.html', context)


    from django.http import Http404
    from django.shortcuts import render
    
    from .models import Question
    # ...
    def detail(request, question_id):
        try:
            question = Question.objects.get(pk=question_id)
        except Question.DoesNotExist:
            raise Http404("Question does not exist")
        return render(request, 'polls/detail.html', {'question': question})

    数据库初始化

    先 python manage.py makemigrations [appname] 
      再 python manage.py migrate [appname]
     
  • 相关阅读:
    Swift学习一
    Swift开发学习(一):初始篇
    objc_msgSend arm64 崩溃问题
    更改navigationController push和pop界面切换动画
    iOS 改变UITextField中光标颜色
    IOS Core Animation Advanced Techniques的学习笔记(五)
    使用CAShapeLayer与UIBezierPath画出想要的图形
    亮相SIGGRAPH 太极拳三维教学App制作揭秘
    MySQL优化——索引
    求职前一个月复习知识
  • 原文地址:https://www.cnblogs.com/slqt/p/9968678.html
Copyright © 2011-2022 走看看