服务发现(Win Server,Android客户端)(Service Discovery (Win Server, Android Clients))
我有一对基本上可以工作的服务器(Windows)和客户端(Android)应用程序,需要在局域网上运行,他们几乎一无所知,直到启动。 关于我能做的唯一假设是WIFI和DHCP分配的IP地址。
我将需要一个客户端找到服务器的机制。 我有一个完整的字母汤的选择,但我以前不必这样做,所以我问你,StackOverflow的优秀人士,寻求建议。
NSD(网络服务发现)似乎是Android上的首选方法,但在Windows上似乎不存在。 是否有可互操作的Windows协议?
我得到的印象是,DNS-SD无法在我的服务器出现之前配置DNS而无法正常工作。
由于我需要知道的只是服务器的IP,所以创建自己的多播组并让服务器宣布自己的方式是非常诱人的。 有没有理由不采用这种方法?
I've got a largely working pair of server (Windows) and client (Android) applications that will need to run on a LAN they will pretty much know nothing about until fired up. About the only assumptions I can make are WIFI and DHCP allocated IP addresses.
I will need a mechanism for the clients to find the server. I've got an entire-alphabet-soup of choices but I've not had to do this before, so I'm asking you, the fine people of StackOverflow, for advice.
NSD (Network Service Discovery) seems to be the preferred method on Android but seems non-existent on Windows. Is there an inter-operable Windows protocol?
I get the impression that DNS-SD wouldn't work for this without configuring the DNS before my server showed up on it.
As all I need to know is the IP of the server, it's very tempting to just make my own multicast group and have the server announce itself way. Is there a reason not to go with this approach?
原文:https://stackoverflow.com/questions/42551834
最满意答案
您可以遍历现有用户,并调用
get_or_create()
:for user in User.objects.all(): UserProfile.objects.get_or_create(user=user)
如果您愿意,可以将其放入数据迁移中 ,或者在shell中运行代码。
You can loop through the existing users, and call
get_or_create()
:for user in User.objects.all(): UserProfile.objects.get_or_create(user=user)
You could put this in a data migration if you wish, or run the code in the shell.
相关问答
更多-
Django缓存用户的配置文件(Django Caching a User's profile)[2022-11-10]
我认为问题与您定义方法的方式有关.... User.profile = property(lambda u: cache_utils.cache_single_object( "user_get_or_create_profile", u.id, get_or_create_profile(u))) 当您访问配置文件属性时,您将始终调用调用以下方法的方法get_or_create_profile(u): return cache_uti ... -
也许你可以添加简单的条件? def create(self, validated_data): user = User.objects.create_user(**validated_data) if validated_data('user_type') == 'student': Student.objects.create(user_id=user.id) else: Teacher.objects.create(user_id=user.id) ...
-
您可以使用ProfileBase的各种方法: var profile = ProfileBase.Create(username); profile.SetPropertyValue("MyGuid", aGuid); profile.SetPropertyValue("MyString", aString); // etc profile.Save() You can use various methods of ProfileBase: var profile = ProfileBase.Create ...
-
您可以遍历现有用户,并调用get_or_create() : for user in User.objects.all(): UserProfile.objects.get_or_create(user=user) 如果您愿意,可以将其放入数据迁移中 ,或者在shell中运行代码。 You can loop through the existing users, and call get_or_create(): for user in User.objects.all(): UserPr ...
-
Django 1.4创建编辑用户配置文件帐户设置视图(Django 1.4 Creating an Edit User Profile Account Settings View)[2022-04-12]
要将配置文件附加到用户对象,您只需要在用户对象上调用get_profile() : user.get_profile() 例如, request.user.get_profile() 关于它的文档在Django Docs中 。 值得注意的是 如果不存在,方法get_profile()不会创建配置文件。 所以你必须有一个触发器来创建用户创建配置文件...... To get the profile attached to a user object, you just need to call get_p ... -
在配置文件夹project_name/urls.py注册您的应用程序的URL:例如: from django.conf.urls import include, url from django.contrib import admin from django.conf import settings urlpatterns = [ url(r'^user/', include('
.urls')), url(r'^admin/', include(admin.site. ... -
用户没有用户配置文件(User has no userprofile)[2022-09-23]
您必须先为用户创建一个用户配置文件: profile = UserProfile.objects.create(user=request.user) 在您的views.py中,您可以使用get_or_create以便在用户没有用户配置文件时为用户创建用户配置文件。 player, created = UserProfile.objects.get_or_create(user=request.user) 更新 :为了在每次创建新用户时自动创建用户配置文件,请使用信号。 在myapp/signals.py ... -
这将是您的重定向URL的正确正则表达式,即。 不要修改你拥有的那个。 url(r'^profile/(?P
\w+)/$', 'pet.views.myprofileview', name="detail_profile") 然后将参数传递给重定向: url = reverse('detail_profile', kwargs={'username': profile.firstname}) return HttpResponseRedirect(url) 这导致还必须定义新视图: d ... -
那么,这取决于你的要求。 如果一个用户只能有一个profile并且你只是想添加一些与user相关的属性,那么没有理由为它创建一个新的类。 但是,即使用户只能拥有一个配置文件,也可能需要执行一些常规操作 。 如果是这样,您可以从users表中删除一些属性以创建表格profiles ,并且您将具有一对一的关系。 class User < ActiveRecord::Base has_one :profile end class Profile < ActiveRecord::Base belongs ...
-
Django - 用户和用户配置文件表单创建两个配置文件而不是一个(Django - User and User Profile form creating two profiles instead of one)[2022-03-13]
你应该摆脱那些信号。 它们没有任何用处,可能是重复的原因。 相反,您需要做一些事情来告诉表单您正在创建的配置文件属于您刚刚创建的用户: user = form.save() profile = profileform.save(commit=False) profile.user = user profile.save() 你还应该去除表单和模型上的save方法 - 定义一个重写方法是没有意义的,它的唯一操作就是调用super方法。 同样,你可以摆脱user is not None和user.is_act ...