编辑:我添加了django-admin.py到我的系统路径(C:\ Users\me\Downloads\Django-1.5.1\django\bin)的路径,但即使在此之后我尝试运行django-admin.py startproject mysite,它要求我选择一个文件打开,甚至当我选择python.py时,它会因为某些原因在chrome中打开.我也试过python django-admin.py startproject mysite,但它说"python:无法打开文件django-admin.py:[Errno 2]没有这样的文件或目录".知道什么是错的吗?
我将python27添加到系统路径中,当我打开cmd并切换到目录(C:\ Users\me\djcode)然后键入django-admin.py startproject mysite时,它说"django-admin.py无法识别作为内部或外部命令,可操作程序或批处理文件".当我尝试输入命令python django-admin.py startproject mysite时,它说"python:无法打开文件django-admin.py:[Errno 2]没有这样的文件或目录"
知道为什么吗?在djangobook(http://www.djangobook.com/en/2.0/chapter02.html)中,如果您通过其setup.py实用程序安装了Django,则说"django-admin.py应该在您的系统路径上"..什么这是否意味着?如何将django-admin.py添加到我的系统路径?我不确定django-admin.py在哪里.
截至目前,我在两个不同的页面上有我的注册表单和登录表单,我似乎无法将它们放在一个视图中,因为我这样做,视图需要不同的返回语句.所以这是我的注册视图功能:
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = MyRegistrationForm()
return render_to_response('register.html', args)
def register_success(request):
return render_to_response('register_success.html')
Run Code Online (Sandbox Code Playgroud)
这是我的登录和身份验证视图:
def login(request):
c = {}
c.update(csrf(request))
return render_to_response('login.html', c)
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/accounts/loggedin')
else:
return HttpResponseRedirect('/accounts/invalid')
Run Code Online (Sandbox Code Playgroud)
以下是登录页面的模板:
<form action="/accounts/auth/" method="post">{% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label …
Run Code Online (Sandbox Code Playgroud) 我有一个批处理文件,它移动一些文件并启动一个程序,由于某种原因,在批处理文件通过其中的所有命令后,它不会关闭.命令提示符在屏幕上保持打开状态,因此我想将其关闭.
我尝试在批处理文件的末尾键入taskkill/IM cmd.exe作为最后一行命令,但它仍然没有关闭cmd.exe,任何想法为什么?应该关闭它吗?这是批处理文件:
@echo off
mkdir C:\Windows\Temp
if exist "C:\Users\" goto win7
if exist "C:\Documents and Settings\" goto winxp
:win7
mkdir C:\folder1
xcopy /s /Y \\server1\Public C:\folder1
C:\folder1\application1
goto exit
:winxp
mkdir "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
mkdir C:\folder1
xcopy /s /Y \\server1\Public C:\folder1
xcopy /s /Y C:\folder1\xp\application1 "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
xcopy /s /Y C:\folder1\xp\application2 "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
"C:\Documents and Settings\All Users\Application Data\Organization\orgapp\application1"
goto exit
:exit
taskkill /IM cmd.exe
Run Code Online (Sandbox Code Playgroud) 从djangobook看这个django代码:
from django.http import Http404, HttpResponse
import datetime
def hours_ahead(request, offset):
try:
offset = int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt)
return HttpResponse(html)
Run Code Online (Sandbox Code Playgroud)
在尝试之后,它将偏移转换为整数,对吧?在'datetime.timedelta(hours = offset)'行中,offset用作整数,但在行'html ='在%s小时(s)中,它将是%s." %(偏移量,dt)'
offset是%s,这是一个字符串,对吗?还是我想念理解?我以为%s只能是一个字符串,而不是一个整数?
好吧,显然VIM是一个非常好的文本编辑器,我想开始将它用于Python.我安装了lubuntu(VM),我做了命令sudo apt-get install vim-gtk,但我现在想知道如何为python设置vim?这记录在哪里?我是linux的新手.有人可以帮我解决这个问题吗?在sudo apt-get install vim-gtk之后的下一步是什么?
我正在创建一个程序来计算数字列表中最高的小数位数.基本上,一个列表[123, 1233]
将返回4,因为1233中有四个数字,它是最大的.另一个例子是[12, 4333, 5, 555555]
返回6因为555555有6个数字.
这是我的代码.
def place(listy):
if len(listy) == 1:
decimal = len(str(listy[0]))
print(decimal)
else:
if len(str(listy[0])) >= len(str(listy[1])):
new_list = listy[0:1]
for i in listy[2:]:
new_list.append(i)
place(new_list)
else:
place(listy[1:])
Run Code Online (Sandbox Code Playgroud)
现在,当我使用print(decimal)
它的工作原理,但如果我更改print(decimal)
到return decimal
,它不返回任何东西.为什么是这样?我该如何解决?我遇到过这些返回语句,它们运行了很多次.提前致谢!