无法导入名称'CommentForm

时间:2016-06-17 07:18:43

标签: python django import

python
    from django.shortcuts import render
    from datetime import datetime
    from .models import Post
    from .forms import PostForm, CommentForm
    from django.shortcuts import render,get_object_or_404
    from django.shortcuts import redirect
    from django.contrib.auth.decorators import login_required


....

def add_comment_to_post(request,pk):
    post = get_object_or_404(Post,pk=pk)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.post = post
            comment.save()
            return redirect('blog.views.post_detail',pk=post.pk)
    else:
        form = CommentForm()
    return render(request,'blog/add_comment_to_post.html',{'form' : form})

我读这门课程的时候 https://github.com/DjangoGirls/tutorial-extensions/blob/master/homework_create_more_models/README.md。 运行此网址

http://localhost:8000/post/5/comment/ 我收到了这个错误。

如何解决这个问题?

===========================================

这是我的/blog/view.py文件

public class DownloadData extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... params) {

    try {
        downloadData("https://blablalabla/get");
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

public void downloadData(String myurl) throws IOException {
    URL u = new URL(myurl);
    InputStream is = u.openStream();

    DataInputStream dis = new DataInputStream(is);

    byte[] buffer = new byte[1024];
    int length;

    OutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/Users/ilknurpc/Desktop/text.docx"));
    while ((length = dis.read(buffer))>0) {
        fos.write(buffer, 0, length);
    }


}
}

0 个答案:

没有答案