django无法访问默认管理部分

 收藏

我正在尝试访问Django默认管理部分,我得到了一个

404 error "not found"

我可以访问默认的django启动页面,该页面告诉我我处于调试模式

如果我尝试通过nginx访问,则在浏览器中收到nginx base 404错误“未找到”,但是我的日志是干净的。

如果我从命令行尝试

links http://127.0.0.1/admin

我收到“连接被拒绝”

(secret) kermit@tuna:~/www/src/exchange $ cat /etc/nginx/sites-available/default 
upstream django {
        server unix:///var/run/uwsgi/exchange.sock; # for a file socket
        #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}


# Default server configuration
#
server {
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;
        root /home/kermit/www/src/exchange;
        index index.html index.htm index.php index.nginx-debian.html;

        server_name tuna.tra.com;

        location / {
                try_files $uri $uri/ =404;
                include     /etc/nginx/uwsgi_params;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        }

        # Django media
        location /media  {
                alias /home/kermit/www/src/exchange/media;  # your Django project's media files - amend as required
        }

        location /static {
                alias /home/kermit/www/src/exchange/static; # your Django project's static files - amend as required
        }

        # Finally, send all non-media requests to the Django server.
        #location / {
        #        uwsgi_pass  django;
        #        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        #}
}

(秘密)kermit @ tuna:〜/ www / src / exchange $ cat exchange / urls.py

from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]

(秘密)kermit @ tuna:〜/ www / src / exchange $ cat exchange / settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'snicker'
DEBUG = True
ALLOWED_HOSTS = ['192.168.42.13','localhost']
# Application definition
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    #mystuff
    'userdash',
#    'userdash.apps.UserdashConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'exchange.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'exchange.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')






(secret) kermit@tuna:~/www/src/exchange $ cat userdash/models.py 
#be sure to run makemigrations and migrate after editing this file
from django.db import models

# Create your models here.

class Product(models.Model):
        title           = models.TextField()
        describtion     = models.TextField()
        price           = models.TextField()
        summary         = models.TextField(default='Bite me wanker!')

如何访问默认的django管理部分?

回复
  • psed 回复

    你试过这个了吗

    替换网址

    http://127.0.0.1/admin
    

    http://127.0.0.1:8000/admin