简体   繁体   中英

Setting up Django admin in visual studio

When I make django project on visual studio there is no admin page. Can anyone help me how to set up the admin page in visual studio? I mean the admin.py page. Which commands should be run. I have tried many methods but none succeeded.

thanks

Saeed

I just started learning Django so this is not as in depth as I would like and was also fairly confused on how to procede when I didn't see it either. After an embarrassing amount of research... Turns out you don't really need the admin.py file to initially access the admin page. You will need one eventually though. So specifically for VS:

  1. make sure you uncommented (or that these exist) in the urls.py:

     from Django.contrib import admin from Django.conf.urls import include #and either, where the admin.py file exists import name_of_another_app.admin # or admin.autodiscover() urlpatterns = [ … # blah, blah, blah url(r'^admin/', include(admin.site.urls)), ]
  2. Now you will need to create a superuser by right clicking the Project (under the solution)

    go into the python menu and click 'Django create superuser ...' and follow the instructions to input a user, email, password.

screenshot of a new project following VS tutorial

in the screenshot there isn't an admin.py file anywhere, however once you run the web server and edit the url by adding /admin to the end you will be able to log in and access the admin page.

If you want an actual admin.py file, you will either have to create one yourself, or as you create new apps an empty one will be generated for you. There you can begin to customize what you need in the admin page.

Hopefully this helps someone!!

To create a superuser:

python manage.py createsuperuser choose a username and create a password.

To register a model in the Django site admin, go to the admin.py inside your app and write:

admin.site.register(<ModelName>) .

Don't forget to import your model: from .models import <ModelName> .

After that, should be able to login in the django site admin and see your model.

Really frustrating issue! Go into command prompt and paste python manage.py startapp hello. A new folder will appear called 'hello' (obv name folder to what you want). This will contain all you need with admin included.

在 Visual Studio 中,在项目模板中,我没有制作 Django Web 项目,而是制作了 Django 空白项目,然后将 Django 应用程序添加到项目中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM