views.py
from nba.models import News
from nba.serializers import NewsSerializers
from rest_framework import viewsets
# Create your views here.
class NewsViewSet(viewsets.ModelViewSet):
queryset = News.objects.all()
serializer_class = NewsSerializers
urls.py
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework.routers import DefaultRouter
from nba import views
router = DefaultRouter()
router.register(r'news', views.NewsViewSet)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/', include('router.urls')),
]
我的django版本是1.8。
当我访问http://127.0.0.1:8000/api时,我没有名为' django.urls'我该怎么办
答案 0 :(得分:0)
在您发布的代码中,没有证据证明您描述的错误是正确的。您应该发布错误以找出哪个文件包含相关导入。
无论如何,升级到Django 1.11,它是当前的LTS Django release。
Django 1.10中存在 var http = require('http');
var fs = require('fs');
var multiparty = require('multiparty');
http.createServer(function (req, res) {
if (req.method === 'POST') {
var form = new multiparty.Form();
form.parse(req, function (err, fields, files) {
/* assuming <input type="file" name="profile" /> is used in upload form */
var profileImageFileArray = files.profile;
if (profileImageFileArray && profileImageFileArray.length > 0) {
var profileImageFile = profileImageFileArray[0];
var tempFilePath = profileImageFile.path;
var newFilePath = __dirname + '/uploads/' + profileImageFile.originalFilename;
fs.readFile(tempFilePath, (err, data) => {
fs.writeFile(newFilePath, data, (err) => {
/* handle response according to success or error */
});
});
}
});
}
else {
var html = fs.readFileSync('index.html');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html);
}}).listen(9090);
。在那之前,它是django.urls
。
不推荐在django.core.urlresolvers模块中导入 赞成其新址,django.urls。
自版本1.10开始不推荐使用:在旧版本中,这些函数是 位于django.core.urlresolvers。从旧位置导入 将继续工作,直到Django 2.0。