小编Mav*_*ick的帖子

Django缩进错误

我是Django的新手,并在教程中尝试了这段代码.但是由于以下错误,我现在无法运行我的程序:

IndentationError at /
('unexpected indent', ('D:\\django_workspace\\django_bookmarks\\..\\django_bookmarks\\bookmarks\\views.py', 14, 4, '    return HttpResponse(output)\n'))
Request Method: GET
Request URL:    http://localhost:8000/
Exception Type: IndentationError
Exception Value:    
('unexpected indent', ('D:\\django_workspace\\django_bookmarks\\..\\django_bookmarks\\bookmarks\\views.py', 14, 4, '    return HttpResponse(output)\n'))
Exception Location: D:\django_workspace\django_bookmarks\..\django_bookmarks\urls.py in <module>, line 2
Python Executable:  C:\Python26\python.exe
Python Version: 2.6.4
Python Path:    ['D:\\django_workspace\\django_bookmarks', 'C:\\Python26', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26\\lib\\site-packages']
Server time:    Tue, 9 Mar 2010 19:18:32 +
Run Code Online (Sandbox Code Playgroud)

我的views.py文件代码是:

from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template …
Run Code Online (Sandbox Code Playgroud)

indentation django-views

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

合并两个HashTable并删除java中的重复项

我有两个带有<int,string>对的Hashtables .现在他们每个都有重复的值,我想合并两个哈希表给我不同的值.我怎样才能做到这一点!?

谢谢 编辑#1我正在从目录中读取文件内容.并将这些内容作为标记存储在两个不同的哈希表中.现在我需要将它们合并到一个哈希表中,这会给我两个表的不同值.

java collections merge hashtable data-structures

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

如何在java中使用jdom从节点中删除子节点?

我有一个 xml 结构如下:

<rurl modify="0" children="yes" index="8" name="R-URL">
    <status>enabled</status>
    <rurl-link priority="3">http</rurl-link>
    <rurl-link priority="5">http://localhost:80</rurl-link>
    <rurl-link priority="4">abc</rurl-link>
    <rurl-link priority="3">b</rurl-link>
    <rurl-link priority="2">a</rurl-link>
    <rurl-link priority="1">newlinkkkkkkk</rurl-link>
</rurl>
Run Code Online (Sandbox Code Playgroud)

现在,我想删除一个子节点,其中 text 等于 http。目前我正在使用此代码:

while(subchilditr.hasNext()){
    Element subchild = (Element)subchilditr.next();
    if (subchild.getText().equalsIgnoreCase(text)) {
        message = subchild.getText();
        update = "Success";
        subchild.removeAttribute("priority");
        subchild.removeContent();
    }
Run Code Online (Sandbox Code Playgroud)

但它并没有完全从 xml 文件中删除子元素。它留给我

<rurl-link/>
Run Code Online (Sandbox Code Playgroud)

有什么建议?

java xml parent-child jdom

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

如何通过PHP获取系统驱动器?

可能重复:
如何在PHP中获取系统信息?

我正在构建一个简单的文件浏览器,我想知道如何通过php脚本获取总驱动器和名称等系统信息?

谢谢

php filesystems

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

创建没有指针别名的编程语言的可能性

我对这里的所有编程爱好者都有一个问题.指针一直存在于编程世界中.就像在C,C++中得到明确的指针支持一样.在java中,显式指针支持不存在,但Java系统内部使用指针.在实际的世界中,是否可以开发一种编程语言来完全没有指针别名?

java compiler-construction code-generation parser-generator

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

如何在不使用表单向导验证表单的情况下转到上一步

我有一个使用sessionwizardviewdjango表单向导构建的多步骤表单,我添加了下一个和上一个按钮,但是问题是,如果我在某个步骤中并且单击上一步时,它要求先填写表单然后可以继续并单击该上一个按钮转到上一步。我无能为力,因为我找不到与我的问题有关的任何东西,我错过了什么吗?

这是几个示例表格:

    from django import forms
    from django.utils.translation import gettext as _

    from addresses.forms import AddressForm, InvoiceAddressForm
    from core.api import NcpAPI
    from django_countries import countries

    api = NcpAPI()
    CHOICES=[('0','Pay by card'), ('1','Invoice')]

    class RegistrationForm(forms.Form):
        title = 'registration'
        first_name      = forms.CharField(label=_("First Name"), widget=forms.TextInput(attrs={'class':'form-text required'}))
        last_name       = forms.CharField(label=_("Last Name"), widget=forms.TextInput(attrs={'class':'form-text required'}))
        registration_company        = forms.CharField(label=_("Company"), widget=forms.TextInput(attrs={'class':'form-text required'}))
        phone           = forms.CharField(label=_("Phone"), widget=forms.TextInput(attrs={'class':'form-text required'}))
        email           = forms.EmailField(label=_("Email"), widget=forms.TextInput(attrs={'class':'form-text required'}))

        def clean_email(self):
            email = self.cleaned_data.get('email')
            if api.is_username_taken(email):
                raise forms.ValidationError(_('Email is in use'))
            return email …
Run Code Online (Sandbox Code Playgroud)

django django-forms django-formwizard django-1.5

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

我不懂程序

我想要一个可以列出目录中所有可用内容的程序.我在java2's.com中找到了一个很好的代码, http://www.java2s.com/Code/Java/File-Input-Output/ListingtheDirectoryContents.htm

这是代码,

import java.io.File;
import java.util.Arrays;

public class Dir {

  static int indentLevel = -1;

  static void listPath(File path) {
    File files[]; 
    indentLevel++; 

    files = path.listFiles();

    Arrays.sort(files);
    for (int i = 0, n = files.length; i < n; i++) {
      for (int indent = 0; indent < indentLevel; indent++) {
        System.out.print("  ");
      }
      System.out.println(files[i].toString());
      if (files[i].isDirectory()) {
        listPath(files[i]);
      }
    }
    indentLevel--; 
  }

  public static void main(String args[]) {
    listPath(new File(".\\code"));
  }
}
Run Code Online (Sandbox Code Playgroud)

我不明白的是n第一个for循环中的变量.如果没有在任何地方定义,那么为什么程序没有显示任何错误?

java

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

java bash命令问题

可能重复:
如何从Java中的Process运行中获取bash命令退出代码?

嗨,我有一个简单的程序使用bash命令解密另一个文件./nv0914 < nv0914.challenge,其中nv0914是一个unix可执行文件,而nv0914.challenge是一个用于解密的文本文件.现在,当我从bash运行它,之后如果我运行命令,echo ${?}我得到一个值0,这是好的.但是现在我必须实施一次攻击,为此我需要通过java程序打印退出值.我现在有这个代码:

import java.io.*;
   import java.util.*;

   public class ExecBashCommand {
     public static void main(String args[]) throws Exception {


       Runtime runtime = Runtime.getRuntime();
       Process process = runtime.exec("./nv0914 < nv0914.challenge");

      /* InputStream is = process.getInputStream();
       InputStreamReader isr = new InputStreamReader(is);
       BufferedReader br = new BufferedReader(isr);
       String line;*/

System.out.println("Exit Code: "+process.exitValue()); 
       //System.out.printf("Output of running %s is:", Arrays.toString(args));

      /* while ((line = br.readLine()) != null) {
         System.out.println(line);
       }*/

     }
    } 
Run Code Online (Sandbox Code Playgroud)

但是这个程序给了我一个错误:

Exception in thread "main" java.lang.IllegalThreadStateException: …
Run Code Online (Sandbox Code Playgroud)

java bash runtime.exec exit-code

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

无法使用drupal form api获取复选框值

我在drupal中有表格,上传图片并且里面有很少的复选框.这是表格:

$form['checklist_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Check List'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,  
  );
$form['checklist_fieldset']['heating'] = array(
   '#type' => 'checkboxes',
   '#title' => t('Heating options'),

   '#options' => array(
  '0' => t('Yes'),
  '1' => t('No')
  ),
   '#description' => t('Heating details.')
  );
Run Code Online (Sandbox Code Playgroud)

这是我的提交功能,我正在处理图像上传和抓取复选框值.我收到成功消息,图像上传但没有获得复选框的值.

function property_add_view_submit($form,&$form_state){
$validators = array();



if($file = file_save_upload('p_file1',$validators,file_direcotry_path)){
$heating = array_keys($form_state['values']['heating']);
drupal_set_message(t('Property Saved! '.$heating));
dpm( $form_state['values']['heating']);
}
Run Code Online (Sandbox Code Playgroud)

drupal drupal-6 drupal-fapi drupal-forms drupal-modules

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

如何监听Nginx上的不同端口并代理请求?

我是 Nginx 配置的新手,我有一个进程,它是一个快速应用程序,使用 pm2 在端口 3000 上运行,我也允许使用 ufw 端口 3000,并在 Nginx 上创建了一个服务器实例来代理它,

    server {
        # SSL configuration

        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name .mysite.co;
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/django/mysite;
        }
        proxy_cache mysite;
        location / {
            include proxy_params;
            proxy_pass http://unix:/home/django/mysite/mysite.sock;
        }
        gzip_comp_level  3;
        gzip_types       text/plain text/css image/*;
        ssl_certificate /etc/letsencrypt/live/mysite.co/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/mysite.co/privkey.pem; # managed by Certbot



    }
    server {
        if ($host = www.mysite.co) {
            return 301 …
Run Code Online (Sandbox Code Playgroud)

https nginx express pm2 nginx-reverse-proxy

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