Dies ist meine erste Frage überhaupt. Ich arbeite in VisualStudio, um eine Django/Python-Anwendung für Smartshopping-AI zu erstellen. Dies ist auch meine erste Python/Django-Technologie-Anwendung. Ich habe Probleme mit der URLs.py und habe gelesen, dass Django-Versionen keine URL-Muster enthalten. Ich habe meine URL-Muster geändert, um den Ratschlag online widerzuspiegeln, und habe meinen django.conf.urls-Import-URL-Abschnitt meines Codes geändert. Es funktioniert immer noch nicht. Bitte helfen Sie.VisualStudio django.conf.urls
Ich habe die Ratschläge, online gehen hier gefolgt:
from datetime import datetime
from django.conf.urls import url
from app.forms import BootstrapAuthenticationForm
# Uncomment the next lines to enable the admin:
from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
# Examples:
url(r'^$', 'app.views.home', name='home'),
url(r'^contact$', 'app.views.contact', name='contact'),
url(r'^about', 'app.views.about', name='about'),
url(r'^login/$',
'django.contrib.auth.views.login',
{
'template_name': 'app/login.html',
'authentication_form': BootstrapAuthenticationForm,
'extra_context':
{
'title':'Log in',
'year':datetime.now().year,
}
},
name='login'),
url(r'^logout$',
'django.contrib.auth.views.logout',
{
'next_page': '/',
},
name='logout'),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
]
ich eine einfache Lösung wollen nicht alle Ansichten zu ändern sind hinzufügen - diese von Visual Studio automatisch generiert wurden. Ich mag autogeneraton weiter zu arbeiten und nur eine einzige Zeile Code hinzufügen, um die url.py
from django.shortcuts import render
from django.http import HttpRequest
from django.template import RequestContext
from datetime import datetime
def home(request):
"""Renders the home page."""
assert isinstance(request, HttpRequest)
return render(
request,
'app/index.html',
context_instance = RequestContext(request,
{
'title':'Home Page',
'year':datetime.now().year,
})
)
def contact(request):
"""Renders the contact page."""
assert isinstance(request, HttpRequest)
return render(
request,
'app/contact.html',
context_instance = RequestContext(request,
{
'title':'Contact',
'message':'Your contact page.',
'year':datetime.now().year,
})
)
def about(request):
"""Renders the about page."""
assert isinstance(request, HttpRequest)
return render(
request,
'app/about.html',
context_instance = RequestContext(request,
{
'title':'About',
'message':'Your application description page.',
'year':datetime.now().year,
})
)
Basierend zu verweisen auf den Antworten und die Stack-Überlauf Antwort auf eine ähnliche Frage (Django URLs error: view must be a callable or a list/tuple in the case of include()) ich diesen Ansatz versucht habe (was noch funktioniert nicht).
from datetime import datetime
from django.conf.urls import url
from app.forms import BootstrapAuthenticationForm
from django.contrib.auth import views as auth_views
from SmartShopper import views as SmartShopper_views
# Uncomment the next lines to enable the admin:
# from django.conf.urls import include
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = [
# Examples:
url(r'^$', SmartShopper_views.home, name='home'),
url(r'^contact$', SmartShopper_views.contact, name='contact'),
url(r'^about', SmartShopper_views.about, name='about'),
url(r'^login/$',
'django.contrib.auth.views.login',
{
'template_name': 'app/login.html',
'authentication_form': BootstrapAuthenticationForm,
'extra_context':
{
'title':'Log in',
'year':datetime.now().year,
}
},
name='login'),
url(r'^logout$',
'django.contrib.auth.views.logout',
{
'next_page': '/',
},
name='logout'),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
[was meine Lösung enthält - ich bin von einer asp.net MVC Hintergrund und django ist ein bisschen mit seinem MVC Typ-Struktur anders kommen noch daran gewöhnen, hilf mir nur thisthing Lauf zu machen! HELPPP bitte. Danke 1
Können Sie bitte hinter dem entsprechenden Code, nicht den Screenshot? Bitte geben Sie auch den relevanten Abschnitt Ihrer 'views.py'-Datei an. – brianpck
yep! Lass mich herausfinden, wie man das schnell macht –